BIG problem if readline strips newlines

William Dandreta wjdandreta at worldnet.att.net
Tue Jun 12 14:28:51 EDT 2001


Hi Pete,
>i've seen frequent mention of an option for readline()
>to strip out newlines as each string is read. this sounds
>like a great idea, but i realized its gonna be very
>difficult to loop through a text file. the standard
>python idioms will no longer work...
>
I don't think it means it changes the file, just the string(s) that are
returned by readline(s)(). Blank lines will be empty strings.

e.g.,

a file like:
-------------
hello

test
-------------------

for lines = file.readlines(chomp=1)

lines will be: ['hello','','test'] instead of the normal
['hello\n','\n','test\n']

The file will not be altered.

Bill





More information about the Python-list mailing list