[Python-Dev] Suggested addition to PEP 8 for context managers
Chris Angelico
rosuav at gmail.com
Mon Apr 16 04:37:57 CEST 2012
On Mon, Apr 16, 2012 at 3:13 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> Instead, the context manager implements a different behavior. It would
> have been better if that behavior had been given a name:
>
> db = sqlite3.connect(filename)
> with auto_commit_or_rollback(db):
> # do a transaction
I agree that it wants a name. If explicitness is the goal, would this
be more suitable?
db = sqlite3.connect(filename)
with db.begin_transaction() as trans:
# do a transaction
This way, if a database engine supports multiple simultaneous
transactions, the same syntax can be used.
Chris Angelico
More information about the Python-Dev
mailing list