"\n" in ASCII-file
bokr at oz.net
Fri Jul 18 23:55:46 CEST 2003
On Fri, 18 Jul 2003 14:28:05 +0200, Karl Scalet <news at yebu.de> wrote:
>Martin P schrieb:
>> for a short exercise-program I have to read the lines in an ASCII-file.
>> But every line has a new-line-feed ("\n") at the end of the line. (The
>> ASCII-file was made with Windows Notepad).
>> Is this only because I used Windows (and Notepad)?
>> And... is there any special method to read lines from a file without "\n"?
>beside the issue about large or not-so-large files, there
>is another difference between Gerhard's line.rstrip() and
>my splitlines() method:
>entire_file.splitlines() preserves trailing whitespace characters
>while line.rstrip() doesn't. Just for the rare case it matters :-)
I guess you could use line.rstrip('\n') in that case, e.g.,
>>> ' line with trailing space \n'.rstrip()
' line with trailing space'
>>> ' line with trailing space \n'.rstrip('\n')
' line with trailing space '
More information about the Python-list