I have a text file:
a aaa aaa a
my desired outcome is:
a N aaa N aaa N a N
I wrote the following”
newf="" with open('testfile.txt','r') as f: for line in f: if len(line) < 87: newf+=line.strip()+" " else: newf+=line.strip()+"Nn" f.close() with open('testfile.txt','w') as f: f.write(newf) f.close()
When I run this my outcome becomes
a aaa aaa a
I cant figure out why it changes the output to one line.
adding an if statement for the space length.