Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将模块的输出从打印模式转换为写入模式_Python_Output - Fatal编程技术网

Python 将模块的输出从打印模式转换为写入模式

Python 将模块的输出从打印模式转换为写入模式,python,output,Python,Output,我一直在尝试使用一个双位阅读器包来提取DNA序列信息,但是我遇到了一个问题。每当我使用twobitreader.twobit_reader模块时,我只能获得打印输出。我想做的是将输出写入一个新文件 以下是有关此模块的信息: twobit_reader获取TwoBitFile类的twobit_文件和“input_stream”,该文件可以是任何可编辑的,包括类似文件的对象写入输出FASTA格式,如果write=None,则使用write print将错误/警告记录到stderr 很可能,我有限的p

我一直在尝试使用一个双位阅读器包来提取DNA序列信息,但是我遇到了一个问题。每当我使用twobitreader.twobit_reader模块时,我只能获得打印输出。我想做的是将输出写入一个新文件

以下是有关此模块的信息: twobit_reader获取TwoBitFile类的twobit_文件和“input_stream”,该文件可以是任何可编辑的,包括类似文件的对象写入输出FASTA格式,如果write=None,则使用write print将错误/警告记录到stderr

很可能,我有限的python编程知识阻碍了我完成这项任务

例如,下面是我编写的一些代码:

    def get_a(n):
      """get sequences from genome"""
      genome = twobitreader.TwoBitFile('hg19.2bit')
      bedfile = open(n+'.bed', 'r')
      o_f = open(n+'_FASTA.txt', 'w')
      twobitreader.twobit_reader(genome, bedfile)
      bedfile.close()
      o_f.close()
这最终会打印出我的序列


如果我试图将twobitreader行更改为:twobitreader.twobit_readergenome,bedfile,o_f以尝试将数据写入文件o_f,则会出现错误“file”对象不可调用。

OP确认此操作有效:

twobitreader.twobit_reader(genome, bedfile, o_f.write)

试试看:twobitreader.twobit\u readergenome,bedfile,o\u f.writeOk我会写一个答案