stdio EOF ?
Jacek Generowicz
jacek.generowicz at cern.ch
Tue Aug 13 09:21:12 EDT 2002
Duncan Booth <duncan at NOSPAMrcp.co.uk> writes:
> Jacek Generowicz <jacek.generowicz at cern.ch> wrote in
> news:tyfd6sn85mt.fsf at pcitapi22.cern.ch:
>
> >> The standard idiom for this is:
> >>
> >> while 1:
> >> line = file.readline()
> >> if not line:
> >> break
> >> ...
> >>
> >> The .readline method of a file object returns a complete line (including
> >> the trailing newline), or an empty string in the case of EOF.
> >
> > ... unfortunately empty lines are meaningful in the relevant context
> > (separation of datasets); an empty line has a meaning different from
> > that of EOF (no more datasets after this one).
> >
>
> I think you misunderstood the bit about empty lines.
You're right ...
> The when the file contains a line that is otherwise blank, the value
> returned is a string containing the newline character.
I forgot about the newline.
All is clear now.
Thanks,
More information about the Python-list
mailing list