readline()/readlines() inconsistent?

Greg Jorgensen gregj at pdxperts.com
Sun Jul 8 18:40:47 EDT 2001


"Carsten Gaebler" <clpy at snakefarm.org> wrote in message
news:3B482C44.6E6EB163 at snakefarm.org...

> I've just come across a strange difference between readline() and
> readlines():
>
> Python 2.1 (#17, Jun 15 2001, 15:24:30)
> [GCC 2.95.2 19991024 (release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> f = open("foobar", "w")
> >>> f.readline()
> ''
> >>> f.close()
> >>>
> >>> f =  open("foobar", "w")
> >>> f.readlines()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IOError: [Errno 9] Bad file descriptor
> >>>
>
>
> Why does readlines() raise an exception while readline() does not? I
> expected it to return an empty list. According to the docs readlines()
> uses readline(). If I open the file "w+" everything's fine. Opinions?


The same thing happens on Windows 2000 with Python 2.1. And xreadlines gives
the same error.

Greg Jorgensen
PDXperts LLC
Portland, Oregon, USA
gregj at pdxperts.com






More information about the Python-list mailing list