This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients jonash, nadeem.vawda, vstinner
Date 2011-09-01.14:28:15
SpamBayes Score 1.110223e-16
Marked as misclassified No
Message-id <1314887296.59.0.6065710393.issue12877@psf.upfronthosting.co.za>
In-reply-to
Content
> 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
History
Date User Action Args
2011-09-01 14:28:16vstinnersetrecipients: + vstinner, nadeem.vawda, jonash
2011-09-01 14:28:16vstinnersetmessageid: <1314887296.59.0.6065710393.issue12877@psf.upfronthosting.co.za>
2011-09-01 14:28:15vstinnerlinkissue12877 messages
2011-09-01 14:28:15vstinnercreate