[Python-ideas] One-line "try with" statement
João Bernardo
jbvsmo at gmail.com
Sun Mar 3 20:06:35 CET 2013
When dealing with files it would be nice to avoid an extra block. This is
not the same as the __exit__ method because you would have to write a
function to just catch an error.
BTW, why not "with...except.."? Just like "for" and "while" loops have
"else" clauses.
with open('foo') as f:
print(f.read())
except IOError:
print('Problem with the file!')
--
João Bernardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130303/25a6cfb6/attachment.html>
More information about the Python-ideas
mailing list