BIG problem if readline strips newlines

Bjorn Pettersen BPettersen at
Tue Jun 12 17:01:06 EDT 2001

> From: Aahz Maruch [mailto:aahz at]
> In article <rFrV6.136199$mu1.27715065 at>,
> Pete Shinners <shredwheat at> wrote:
> >
> >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...
> >
> >for line in file.readlines(chomp=1):
> >    pass
> Um.  Think again?  Why wouldn't this work?

I think he meant:

  while 1:
    line = file.readline(chomp=1)
    if not line: break

-- bjorn

More information about the Python-list mailing list