Seekable files
Steven D'Aprano
steve at pearwood.info
Tue Mar 15 06:35:36 EDT 2016
Suppose somebody passes me an open file handle. What's the right way to tell
if it is seekable in Python 2?
I see that stdin has a seek and tell method, but they raise:
py> sys.stdin.tell()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 29] Illegal seek
Are seek and tell guaranteed to exist on all files?
Is there some other way to tell whether the file supports seeking other than
to try it and see?
(In Python 3, files have a seekable method.)
--
Steven
More information about the Python-list
mailing list