これは私の初めてのpythonのを使用していますが、どこが間違っているのかわかりません。ここに私のコードは次のとおりです。Python argparseエラー
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser(description='Example of argparse')
parser.add_argument('-i','--input', help='Input fasta file', required=True)
parser.add_argument('-o','--output', help='Output text file', required=True)
args = parser.parse_args()
genes = {} # empty list
with open(input, 'r') as fh_in:
for line in fh_in:
line = line.strip()
if line[0] == ">":
gene_names = line[1:]
genes[gene_names] = ''
else:
genes[gene_names]+=line
for (name,val) in genes.items():
with open(output, "w") as fh_out:
val = len(val)
fh_out.write('%s %s' % (name,val))
fh_out.write("\n")
と私はそれを実行しようとすると、私は
python get_gene_length.py -i test_in.fa -o test_out.txt
Traceback (most recent call last):
File "get_gene_length.py", line 13, in <module>
with open(input, 'r') as fh_in:
TypeError: coercing to Unicode: need string or buffer, builtin_function_or_method found
このエラーを取得する誰もが、私はそれを動作させるために、スクリプトに変更を加える必要があるところ、私が理解するのに役立つことはできますか?
入力をargs.inputに変更した後も同様に出力されました。これは大きな助けです! – upendra