by Random_Person · 16y ago · 0 comments
in_file = open('c:\original.txt', 'r')
out_file = open('c:\output.txt', 'w')
for line in in_file.readlines():
out_file.write('<tr> bgcolor="006699">')
out_file.write(' <td>' + line[0:12] + '<td>')
in_file.close()
out_file.close()
There will be more text written per execution of the loop, but I can handle that coding. :)What I can't grasp is why write doesn't start a newline and what I can do to remedy that. Currently this is just making a huge line of text instead of individual lines.
Thanks a ton!
Okay, so, stripping spaces from string values. Easy? If I import my line, I have 6 strings I need to segment out of it and my file uses spaces. So, in my previous line:
out_file.write(' <td>' + line[0:12] + '<td>\n')
I'd like to strip the spaces from line[0:12]Thanks!
line[0:12].strip()
but see my other comment about str.split().