Python output on a separate lines -
i have simple question python. wrote working script when execute it, gives me answer in 1 line, string. looking answer on 2 separate lines. here code: python code
def test(): fh=open('xxxxxxx.txt', 'r') fo=open('output.txt', 'a') line in fh: line=line.strip() if(line.startswith('total sequences')): fo.write(line) fh.close() fh2=open('xxxxxxx.txt', 'r') fo2=open('output.txt', 'a') line in fh2: line=line.strip() if(line.startswith('sequence length')): fo2.write(line) fh2.close() print(test())
you removing newline characters "\n" each line in file statement:-
line=line.strip()
just remove , should work correctly.
Comments
Post a Comment