简体   繁体   中英

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).

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() ? H() is also called inside run() .

Third: H() does not have any return value. You assign the return value to data in run() but there is no such return value. I guess you want to add return candidates at the end of your function H() .

Fourth: You should use 'a' instead of 'wb' as file opening mode since you want to append every single line instead of overwriting it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM