尝试创建fi时出错

2024-05-19 17:38:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个程序,将一个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

Tags: fromimport程序datarecordseqdnarna
1条回答
网友
1楼 · 发布于 2024-05-19 17:38:31

首先,您必须在python中定义f,然后才能尝试在其上编写任何内容:

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

其中filename.txt是文件的名称和格式,“w”称为模式,我们用于在文件中写入,如果您想读取文件,可以使用“r”模式

你可以在这个链接https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files上阅读更多内容

相关问题 更多 >