[New-bugs-announce] [issue4579] .read() and .readline() differ in failing
Mark Florisson
report at bugs.python.org
Sun Dec 7 20:06:31 CET 2008
New submission from Mark Florisson <markflorisson88 at gmail.com>:
>>> f = os.fdopen(os.open('spam!', os.O_TRUNC|os.O_CREAT|os.O_RDWR), 'w')
>>> f.read()
''
>>> f.readline()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
>>> f.write("spamspamhihi")
>>> f.read()
''
>>> f.seek(0)
>>> f.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
This is very strange behaviour. First, .read() succeeds, and .readline()
fails, but after writing and seeking, .read() also fails.
In python3, both read and readline fail, but with different exceptions:
>>> f = os.fdopen(os.open('spam!', os.O_TRUNC|os.O_CREAT|os.O_RDWR), 'w')
>>> f.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mark/source/code/_python-3.0/Lib/io.py", line 1718, in read
decoder.decode(self.buffer.read(), final=True))
File "/home/mark/source/code/_python-3.0/Lib/io.py", line 668, in read
self._unsupported("read")
File "/home/mark/source/code/_python-3.0/Lib/io.py", line 327, in
_unsupported
(self.__class__.__name__, name))
io.UnsupportedOperation: BufferedWriter.read() not supported
>>> f.readline()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mark/source/code/_python-3.0/Lib/io.py", line 1807, in
readline
while self._read_chunk():
File "/home/mark/source/code/_python-3.0/Lib/io.py", line 1554, in
_read_chunk
input_chunk = self.buffer.read1(self._CHUNK_SIZE)
AttributeError: 'BufferedWriter' object has no attribute 'read1'
In my opinion, all operations, in all python versions, should fail like
readline in the first example: IOError: [Errno 9] Bad file descriptor
----------
messages: 77242
nosy: eggy
severity: normal
status: open
title: .read() and .readline() differ in failing
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 3.0
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4579>
_______________________________________
More information about the New-bugs-announce
mailing list