Python包含外壳程序路径文件名

问题描述 投票:0回答:2

这是我在shell中的代码,并且包含python命令:

for file in `ls $FOLDER`
do
    echo "$file"
    var=`python -c "from Bio import SeqIO, SeqUtils; import os; rec = SeqIO.read("**$FOLDER/$file**", 'fasta'); SeqUtils.xGC_skew(rec.seq, 220000)" `
done

而且我不知道如何使python识别我的文件名

python shell path command
2个回答
1
投票

您需要在python代码中转义双引号:

for file in `ls $FOLDER`
do
    echo "$file"
    var=`python -c "from Bio import SeqIO, SeqUtils; import os; rec = SeqIO.read(\"$FOLDER/$file\", 'fasta'); SeqUtils.xGC_skew(rec.seq, 220000)" `
done

0
投票

我看到一些常见的shell错误:

  • Don't parse ls。采用
    ls
  • 使用for file in "$FOLDER"/*; ... 而不是$(...)-易于阅读,易于嵌套。 `...`
  • 摆脱使用ALLCAPS变量名的习惯,将那些保留为Shell保留。有一天,您将先写Reference,然后写PATH=something
© www.soinside.com 2019 - 2024. All rights reserved.