I have some data printed out by some software and it has given me too many extra new lines. I'm trying to remove all extra new line characters whilst maintaining the column format of the following data:
[atRA]_0 [Cyp26A1_mRNA]_0
1 0 0
1.999 0 0
2.998 0 0
3.997 0 0
4.996 0 0
This code simply doesn't work
def remove_newline_from_copasi_report(self,copasi_data):
with open(copasi_data) as f:
lines=[]
data = f.read()
return data.rstrip()
Whereas this code removes all new lines and ruins the format:
def remove_newline_from_copasi_report(self,copasi_data):
with open(copasi_data) as f:
lines=[]
data = f.read()
return data.replace('\n','')
Does anybody know how to remove all but one newline character from each line of my text file?
Thanks
data.replace('\n\n','')maybe?