python file API

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Sep 25 06:38:35 EDT 2012


On 25 September 2012 08:27, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:

> On 25/09/2012 03:32, Mark Adam wrote:
>
>> On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
>> <oscar.j.benjamin at gmail.com> wrote:
>>
>>> try:
>>>      f.pos = 256
>>> except IOError:
>>>      print('Unseekable file')
>>
>>
> Something along these lines http://docs.python.org/dev/**
> whatsnew/3.3.html#pep-3151-**reworking-the-os-and-io-**exception-hierarchy<http://docs.python.org/dev/whatsnew/3.3.html#pep-3151-reworking-the-os-and-io-exception-hierarchy>?


I just tried to find out what error would be raised by seeking on a file
that doesn't support seeking and II think it's just OSError in the reworked
hierarchy. The error in Python 2.7 is

Traceback (most recent call last):
  File "tmp.py", line 2, in <module>
    sys.stdin.seek(5)
IOError: [Errno 29] Illegal seek

This corresponds to ESPIPE from errno.h which isn't referred to anywhere in
pip 3151:
http://www.python.org/dev/peps/pep-3151/

So I guess it would still need to be

try:
    f.pos = 256
except OSError as e:
    if e.errno != 29:
        raise
    print('Unseekable file')

Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120925/94c65c66/attachment.html>


More information about the Python-list mailing list