Message77242
>>> 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 |
|
Date |
User |
Action |
Args |
2008-12-07 19:06:32 | eggy | set | recipients:
+ eggy |
2008-12-07 19:06:31 | eggy | set | messageid: <1228676791.35.0.647481208562.issue4579@psf.upfronthosting.co.za> |
2008-12-07 19:06:30 | eggy | link | issue4579 messages |
2008-12-07 19:06:29 | eggy | create | |
|