<div dir="ltr"><div><div><div><div>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.<br>BTW, why not "with...except.."? Just like "for" and "while" loops
have "else" clauses.<br><span style="font-family:courier new,monospace"><br></span></div><span style="font-family:courier new,monospace"> with open('foo') as f:<br></span></div><span style="font-family:courier new,monospace"> print(f.read())<br>
</span></div><span style="font-family:courier new,monospace"> except IOError:<br></span></div><span style="font-family:courier new,monospace"> print('Problem with the file!')</span><br><div class="gmail_extra">
<br clear="all"><div>--<br>Joćo Bernardo</div>
<br></div></div>