[英]Trying to write output file but not getting any data in output file in python
I am trying to write output file but not getting any output in file.Using below code I am not able to write the data in output file. 我正在尝试写入输出文件,但没有在文件中获得任何输出。使用下面的代码,我无法将数据写入输出文件中。 Please check my code: In this script i am trying to do some bioinformatics analysis. 请检查我的代码:在此脚本中,我尝试进行一些生物信息学分析。 1. The first line contains the name of the protein and the count of subsequent lines of output for this protein (say N) 2. Each of the next N lines contains a match information: the locations of the GBoxes and the actual matches (remember there are perturbations and X's, ie wild cards, that are allowed). 1.第一行包含蛋白质的名称和该蛋白质输出的后续行的计数(例如N)。2.接下来的N行中的每行均包含一个匹配信息:GBoxes的位置和实际匹配项(请记住有扰动和X(即通配符)被允许)。
I am getting expected output but not able to write output data in file. 我正在获得预期的输出,但无法在文件中写入输出数据。
Script 脚本
def write_file(data):
file_name = r'C:\Users\Vishnu\Desktop\Hiral_project_analysis\output_1.txt'
with open(file_name, 'wb') as x_file:
x_file.write('{}'.format(data))
def run():
data = H(protein,x1,x2,x3,x4, protein_name)
write_file(data)
First you should get your indentations right (if it's not a copy&paste problem here). 首先,您应该正确设置缩进(如果这里不是复制粘贴问题)。
Second: Why are you calling H()
before run()
? 第二:为什么要在run()
之前调用H()
run()
? H()
is also called inside run()
. H()
也称为run()
内部。
Third: H()
does not have any return value. 第三: H()
没有任何返回值。 You assign the return value to data
in run()
but there is no such return value. 您将返回值分配给run()
data
,但是没有此类返回值。 I guess you want to add return candidates
at the end of your function H()
. 我猜您想在函数H()
的末尾添加return candidates
。
Fourth: You should use 'a'
instead of 'wb'
as file opening mode since you want to append every single line instead of overwriting it. 第四:您应该使用'a'
而不是'wb'
作为文件打开模式,因为您要追加每行而不是覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.