python3.3运行错误argument error,怎么处理啊?

错误提示如下:argumenterror./*.pyfile.kodataFile.data45Traceback(mostrecentcalllast):File"<p... 错误提示如下:
argument error
./*.py file.ko dataFile.data
45
Traceback (most recent call last):
File "<pyshell#7>", line 4, in <module>
sys.exit(1)
SystemExit: 1
我代码的目的是想把file.ko文件中某些gene数据的ko信息投射到dataFile.data文件里去。dataFile.data里的gene数据是file.ko的子集,但是缺少注释。
代码如下:
>>> import sys
>>> usage = """./*.py file.ko dataFile.data """
>>> def readKo(file): #construct a ko diction
f = open(file, 'r')
koDic = {}
for line in f:
line = line.strip("\n")
words = line.split("\t")
gene = words[0]
ko = words[1]
koDic[gene] = ko #{gene: ko}
f.close()
return koDic

>>> def printToFile(dataFile, koDic): #read the data file and append the ko number to it
f = open(dataFile, 'r')
for line in f:
line = line.strip("\n")
words = line.split("\t")
if koDic.has_key(words[0]):
sys.stdout.write("%s\t%s\n"%(line, koDic[words[0]]))
else:
sys.stderr.write("%s has no ko number\n"%words[0])
f.close()

>>> if __name__ == '__main__':
if len(sys.argv) != 3:
sys.stderr.write("argument error\n%s\n"%usage)
sys.exit(1)
koDic = readKo(sys.argv[1])
printToFile(sys.argv[2], koDic)

argument error
./*.py file.ko dataFile.data
45
Traceback (most recent call last):
File "<pyshell#7>", line 4, in <module>
sys.exit(1)
SystemExit: 1
>>>
展开
 我来答
271680114
2013-09-23 · TA获得超过466个赞
知道小有建树答主
回答量:248
采纳率:0%
帮助的人:212万
展开全部

创建文件print_file.py

import sys
usage = """./*.py file.ko dataFile.data """
def readKo(file):       #construct a ko diction
    f = open(file, 'r')
    koDic = {}
    for line in f:
        line = line.strip("\n")
        words = line.split("\t")
        gene = words[0]         
        ko = words[1]
        koDic[gene] = ko        #{gene: ko}
    f.close()
    return koDic

def printToFile(dataFile, koDic):   #read the data file and append the ko number to it
    f = open(dataFile, 'r')
    for line in f:
        line = line.strip("\n")
        words = line.split("\t")
        if koDic.has_key(words[0]):
           sys.stdout.write("%s\t%s\n"%(line, koDic[words[0]]))
        else:
           sys.stderr.write("%s has no ko number\n"%words[0])
    f.close()

if __name__ == '__main__':
    if len(sys.argv) != 3:
        sys.stderr.write("argument error\n%s\n"%usage)
        sys.exit(1)
    koDic = readKo(sys.argv[1])
    printToFile(sys.argv[2], koDic)

然后在shell中执行

python print_file.py file.ko dataFile.data


if __name__ == '__main__'

这个东西是在文件中用的,而且你调用sys.argv[1]和sys.argv[2]就是你运行时输入的两参数

更多追问追答
追问
我按照你的方法,创建print_file.py保存后再运行
>>> python print_file.py file.ko dataFile.data
SyntaxError: invalid syntax
提示还是错误哎,错误在print_file
请问你知道怎么解决么?
追答
错误提示只有这一行吗,把其他的错误提示也发出来我看下
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式