Default scope of variables

Chris Angelico rosuav at gmail.com
Tue Jul 9 07:07:29 CEST 2013


On Tue, Jul 9, 2013 at 2:52 PM, alex23 <wuwei23 at gmail.com> wrote:
> with new_transaction(conn) as folder_tran:
>     folder_tran.query("blah")
>     with folder_tran.subtransaction() as file_tran:
>         file_tran.query("blah")
>         with file_tran.subtransaction() as type_tran:
>             type_tran.query("blah")

Warp my code around a language limitation? Only if I absolutely have to.

The subtransactions are NOT concepted as separate transactions. They
are effectively the database equivalent of a try/except block. Would
you want to have to use a different name for a builtin just because
you're inside a try block?

a = int("123")
try:
    b = int1(user_input)
except ValueError:
    b = 0
c = int("234")

No. That assignment to b should be int(), same as a and c.

ChrisA



More information about the Python-list mailing list