
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
>>> 展开
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
>>> 展开
1个回答
展开全部
创建文件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
请问你知道怎么解决么?
追答
错误提示只有这一行吗,把其他的错误提示也发出来我看下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询