Python DB API - commit() v. execute("commit transaction")?

Ian Kelly ian.g.kelly at gmail.com
Tue May 30 11:09:50 EDT 2017


On Tue, May 30, 2017 at 8:21 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, May 31, 2017 at 12:12 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> There's no difference I'm aware of in the implementations I've used,
>> but having a consistent API does allow for constructions such as:
>>
>> try:
>>     do_stuff(conn)
>> except:
>>     conn.rollback()
>> finally:
>>     conn.commit()
>>
>> without having to worry about variations in syntax between databases.
>
> I prefer:
>
> with conn, conn.cursor() as cur:
>     do_stuff(cur)

As do I, but it's not as clear what that does and the use as context
managers is also not explicitly supported by PEP 249.



More information about the Python-list mailing list