Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75917 > unrolled thread

Re: Newbie needing some help

Started byChris Angelico <rosuav@gmail.com>
First post2014-08-09 10:13 +1000
Last post2014-08-09 10:13 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Newbie needing some help Chris Angelico <rosuav@gmail.com> - 2014-08-09 10:13 +1000

#75917 — Re: Newbie needing some help

FromChris Angelico <rosuav@gmail.com>
Date2014-08-09 10:13 +1000
SubjectRe: Newbie needing some help
Message-ID<mailman.12773.1407543213.18130.python-list@python.org>
On Sat, Aug 9, 2014 at 9:55 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
> try:
>     action
>     commit
> finally:
>     rollback

If commit/rollback automatically opens a new transaction, this would
just roll back an empty transaction - not a big deal. But yes, I do
see what you're looking at here.

However, structures like this are necessary only if you're hanging
onto the database connection. Python gives you a well-defined
unhandled-exception handler, and it's easy to just let exceptions
happen - if something goes wrong, you won't commit, and you'll get a
helpful traceback on the console. My recommended model for Python
databasing is:

Create database connection, get cursor
while "work to do":
    do work
Commit

Until such time as you have a demonstrable need for more complexity,
this model is safe, simple, and easy to work with. And less code
generally means less bugs :)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web