python file API
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Sep 24 18:55:59 EDT 2012
On 24 September 2012 23:41, Mark Adam <dreamingforward at gmail.com> wrote:
> > seek() and tell() can raise exceptions on some files. Exposing pos as an
> > attribute and allowing it to be manipulated with attribute access gives
> the
> > impression that it is always meaningful to do so.
>
> It's a good point, python already is allowing exceptions to be caught
> within "properties", so exceptions from such an attribute could
> presumably be handled similarly.
>
There are many situations where a little bit of attribute access magic is a
good thing. However, operations that involve the underlying OS and that are
prone to raising exceptions even in bug free code should not be performed
implicitly like this. I find the following a little cryptic:
try:
f.pos = 256
except IOError:
print('Unseekable file')
Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120924/b94fcd29/attachment.html>
More information about the Python-list
mailing list