A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-April/118756.html below:

[Python-Dev] Suggested addition to PEP 8 for context managers

[Python-Dev] Suggested addition to PEP 8 for context managers [Python-Dev] Suggested addition to PEP 8 for context managersChris 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4