0

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, i.e. 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)
1
  • Did you try tracing (usually using print) the value of data in run() after calling H()? Note that you call H() in the for loop without capturing the return value, then you call run() which also calls H() again. Commented Oct 23, 2017 at 13:40

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Dear Can you please explain me with example? I am new in python
@vishnu: the explanation in this answer should be clear to anyone who has written the code you show. If you don't know about return or file opening modes then you should follow a basic python tutorial.
Good. Then you should accept the answer as solution.
@lebenlechzer, Dear Can you please suggest me how to save multiple graphs in output directory ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.