首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >木星笔记本里的生物巨蟒?Windows 7

木星笔记本里的生物巨蟒?Windows 7
EN

Stack Overflow用户
提问于 2017-02-09 21:48:51
回答 1查看 1.6K关注 0票数 1

我已经在windows和Anaconda上安装了Python版本3.6。我想在朱庇特笔记本中的代码中使用Biopython软件包。我还使用以下命令安装了biopython:

代码语言:javascript
复制
conda install -c anaconda biopython=1.68

当我想在下面运行我的代码时,它不起作用。fasta只是一个包含序列的文件。

代码语言:javascript
复制
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

它应该输出这些序列,但它说:

代码语言:javascript
复制
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'

拜托,谁来帮我摆脱这一切!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-10 15:26:42

问题是,示例代码只适用于Python 2。

Python3取消了迭代器类上的.next()方法,您应该使用内置函数next(...) (在Python2.6之前可用)。

试一试next(record_iterator)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42147501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档