首页 > 解决方案 > Python包含shell路径文件名

问题描述

这是我在 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识别我的文件名

标签: pythonshellpathcommand

解决方案


您需要在 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

推荐阅读