Ian Kelly <ian.g.ke...@gmail.com>:

> It's good practice to keep your try blocks as narrow as possible in
> any case.

True. Unfortunately, that leads to trouble with the handy "with"
construct:

    with open(path) as f:
        ...

If the open() call is guarded against exceptions (as it usually should),
one must revert to the classic syntax:

    try:
         f = open(path)
    except IOError:
         ...
    try:
         ...
    finally:
         f.close()


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to