传递参数时出错

时间:2014-10-22 16:54:56

标签: python python-2.7

import sys
import argparse
import ORFALGO as orf
#get filenames from command line arguments
firstSeq = sys.argv[1]
if len(sys.argv)>=3:
    resultFile = sys.argv[2]
else:
    resultFile='ORF.txt'
def parse_fasta(fasta): 
        sequences=''
        sep=''
        with open(fasta) as f:
            next(f)
            for line in f:
                sequences += (line.strip())
        return sequences
seq= parse_fasta(firstSeq)

File "C:\Users\ram\Desktop\python\hw2\ass2\LongORF.py", line 6, in <module>
    firstSeq = sys.argv[1]
IndexError: list index out of range

2 个答案:

答案 0 :(得分:0)

sys.argv[0]是您的脚本名称,在调用脚本时应至少提供一个参数。 目前sys.argv没有index = 1元素,因此发生错误。

答案 1 :(得分:0)

您需要将其作为

运行
python LongORF.py firstSeq resultFile

下面

LongORF.py是sys.argv[0] firstSeq是sys.argv[1] resultFile是sys.argv[2]