尝试创建文件时出错

时间:2017-09-28 19:47:07

标签: python python-2.7

我创建了这个程序,您可以将DNA序列从文件转换为RNA,然后创建一个存储有RNA的文件。我有这个错误,

f.write(mRNA_str)

NameError: name 'f' is not defined


from Bio.Seq import Seq
from Bio import SeqIO

Dna_Wild_str = raw_input(" Enter File :" )
Wild_Data_str = open(Dna_Wild_str)

listt = []
for record in SeqIO.parse(Wild_Data_str,'fasta'):
seq = record.seq
mRNA_str = Seq.transcribe(seq)
print "Sequence:", mRNA_str
f.write(mRNA_str)
f.close

1 个答案:

答案 0 :(得分:0)

首先,在尝试在其上编写任何内容之前,必须在python中定义f:

f = open('filename.txt', 'w')

其中,filename.txt是您文件的名称和格式,而且' w'我们用来写文件的模式,如果你想阅读你可以使用的文件' r'模式。

您可以在此链接https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

上阅读更多内容
相关问题