readline()/readlines() inconsistent?
Carsten Gaebler
clpy at snakefarm.org
Sun Jul 8 05:47:48 EDT 2001
Hi there!
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?
Regards
Carsten.
More information about the Python-list
mailing list