New submission from Mark Florisson <[EMAIL PROTECTED]>:

>>> 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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue4579>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to