[issue12877] Popen(...).stdout.seek(...) throws "Illegal seek"
STINNER Victor
report at bugs.python.org
Thu Sep 1 16:28:16 CEST 2011
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> Why does it have a 'seek' method then?
Python doesn't remove a method if the operation is forbidden. For example, Python doesn't remove write() method if the file is read only, and it doesn't remove most methods after close().
I prefer to have files with always the same API. I think that it's more practical.
Note: Text files of the io module (TextIOWrapper) raises io.UnsupportedOperation on seek() if the file is not seekable (e.g. if the file is a pipe):
$ ~/prog/python/default/python
Python 3.3.0a0 (default:d26c7b18fc9d, Jul 22 2011, 12:04:31)
>>> import os
>>> a,b=os.pipe()
>>> f=os.fdopen(a, 'rb')
>>> f
<_io.BufferedReader name=3>
>>> f.seek(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 29] Illegal seek
>>> f2=os.fdopen(a, 'r')
>>> f2
<_io.TextIOWrapper name=3 mode='r' encoding='UTF-8'>
>>> f2.seek(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
io.UnsupportedOperation: underlying stream is not seekable
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12877>
_______________________________________
More information about the Python-bugs-list
mailing list