launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #02573
Re: The with statement
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jeroen Vermeulen wrote:
> Aaron Bentley wrote:
>
>> ISTM that try/finally is just syntactic sugar for try/except+raise/else,
>> and that context managers handle the latter just fine.
>
> But to my taste not very transparently, is my point.
On the other hand, context managers can make the right way to do it also
the lazy way to do it.
One alternative to using a context manager for transactions is:
txn = transaction.begin()
try:
modify_the_database()
finally:
# Ah, everything succeeded.
txn.commit()
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkt1dv0ACgkQ0F+nu1YWqI0m9ACeOzahsnsn+wa6pqWirSYWHlPI
HkgAniXGYEfeZenCR5SWuWVYDFJVS+r9
=dlFk
-----END PGP SIGNATURE-----
Follow ups
References