First of all, there is universal newline support
Secondly: use line.strip()
. Use line.rstrip('\r\n')
if you want to keep spaces at the beginning or end of a line.
Oh and
print '"%s"' % line
or at least
print '"' + line + '"'
may seem a little nicer.
You can iterate over the lines in such a file (this will not break into empty lines in the middle of the file, like your code):
for line in f:
print '"' + line.strip('\r\n') + '"'
, , str.splitlines
:
with open('input.txt', 'rU') as f:
for line in f.read().splitlines():
print '"%s"' % line