开发者社区> 问答> 正文

python 打印序列时出错? 400 报错

python 打印序列时出错? 400 报错

python 初学者问题    在学习时用这个代码打印时,就打印第一条序列,然后就出错了,请给与解答,谢谢!
>>> handle=open('c:/python2.7/Doc/target.fa','r')
>>> for seq_record in SeqIO.parse(handle,'fasta'):
         print seq_record.id
         print repr(seq_record.seq)
         print len(seq_record)
         handle.close()

         
GRMZM2G567718_T01
Seq('AAAGCCAAAGGAGAGAGAGAGGATTGGAAAATGAGTTCGAATATGCTGATAAAC...ATG', SingleLetterAlphabet())
435

Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    for seq_record in SeqIO.parse(handle,'fasta'):
  File "C:\python2.7\lib\site-packages\Bio\SeqIO\__init__.py", line 582, in parse
    for r in i:
  File "C:\python2.7\lib\site-packages\Bio\SeqIO\FastaIO.py", line 115, in FastaIterator
    for title, sequence in SimpleFastaParser(handle):
  File "C:\python2.7\lib\site-packages\Bio\SeqIO\FastaIO.py", line 53, in SimpleFastaParser
    line = handle.readline()
ValueError: I/O operation on closed file

展开
收起
爱吃鱼的程序员 2020-05-29 20:07:32 342 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    >>> handle=open('c:/python2.7/Doc/target.fa','r')
    >>> for seq_record in SeqIO.parse(handle,'fasta'):
             print seq_record.id
             print repr(seq_record.seq)
             print len(seq_record)
             handle.close()  #这里,每次循环进来都关闭一次?



    ######的######缩进问题?######确实是######哦!谢谢啊!刚开始学,不太懂,我看教程上是这么写的,非常感谢啊!
    2020-05-29 20:07:34
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载