Message143329
> 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 |
|
Date |
User |
Action |
Args |
2011-09-01 14:28:16 | vstinner | set | recipients:
+ vstinner, nadeem.vawda, jonash |
2011-09-01 14:28:16 | vstinner | set | messageid: <1314887296.59.0.6065710393.issue12877@psf.upfronthosting.co.za> |
2011-09-01 14:28:15 | vstinner | link | issue12877 messages |
2011-09-01 14:28:15 | vstinner | create | |
|