我已经在windows和Anaconda上安装了Python版本3.6。我想在朱庇特笔记本中的代码中使用Biopython软件包。我还使用以下命令安装了biopython:
conda install -c anaconda biopython=1.68当我想在下面运行我的代码时,它不起作用。fasta只是一个包含序列的文件。
from Bio import SeqIO
handle = open("Q1.fasta")
record_iterator = SeqIO.parse(handle, "fasta")
seq1_20 = record_iterator.next()
seq2_20 = record_iterator.next()
seq3_20 = record_iterator.next()
seq1_100 = record_iterator.next()
seq2_100 = record_iterator.next()
handle.close()
print seq1_20
print seq2_20
print seq3_20
print seq1_100
print seq2_100它应该输出这些序列,但它说:
AttributeError
Traceback (most recent call last)
<ipython-input-4-d5af48173555> in <module>()
2 handle = open("Q1.fasta")
3 record_iterator = SeqIO.parse(handle, "fasta")
----> 4 seq1_20 = record_iterator.next()
5 seq2_20 = record_iterator.next()
6 seq3_20 = record_iterator.next()
AttributeError: 'generator' object has no attribute 'next'拜托,谁来帮我摆脱这一切!
发布于 2017-02-10 15:26:42
问题是,示例代码只适用于Python 2。
Python3取消了迭代器类上的.next()方法,您应该使用内置函数next(...) (在Python2.6之前可用)。
试一试next(record_iterator)。
https://stackoverflow.com/questions/42147501
复制相似问题