sorry, my reply to all button goofed up On Sat, Jun 26, 2010 at 7:43 PM, Steven D'Aprano <st...@pearwood.info>wrote:
> Hi Christopher, > > Are you aware you have written directly to me instead of the tutor > mailing list? It's normally considered rude to do so, unless your > message truly is meant to be private. > > > On Sun, 27 Jun 2010 09:24:22 am you wrote: > > what about more complex cleanup code, like saving data or showing a > > error message > > how would the with statement coop with that > > Exactly the same as simple cleanup code. Just be careful not to rely on > things which may not have happened inside the try block. E.g. this > won't work: > > x = something() > try: > y = x - 8 > z = 100/y > finally: > write_data_file(x, y, z) > > This will fail if something() returns 8, because z won't be defined, and > your cleanup block itself will raise a NameError exception. > > > -- > Steven D'Aprano >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor