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


Groups > comp.lang.python > #75917

Re: Newbie needing some help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'finally:': 0.07; 'subject:help': 0.08; '"work': 0.09; 'cursor': 0.09; 'try:': 0.09; 'wrong,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'complexity,': 0.16; 'demonstrable': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handler,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'commit': 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'helpful': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'code': 0.31; 'exceptions': 0.31; 'subject:some': 0.31; 'bugs': 0.33; 'transaction': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:u 10': 0.60; 'easy': 0.60; 'simple,': 0.60; 'new': 0.61; "you're": 0.61; 'back': 0.62; "you'll": 0.62; 'such': 0.63; 'happen': 0.63; 'more': 0.64; 'connection.': 0.74; 'hanging': 0.84; 'opens': 0.91; 'to:none': 0.92; 'connection,': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=/m0chh+kfgFryvIas3JgrVCTZ/8WAp6RXDTd3ePkgBc=; b=MLQmXOmBpeosocAhW+XpT3Qque/ZhJjiN6rmeTTUeABYXVmZJP0SukUrboSmhUFbdP RS6VGV/ZGnvfpcWxjbhD4RrG5cUKMtp4McAQ7xxRElh2MMWKLUNy+3QSK/ksdSi9RgQZ ZiXFZa8mAzokceodo7AhENzuWxI18muMV7rCbiltNVvjujzE+UfGfl4H76x0cPbs7tBt BwUz9z6ZavKQti57nhAOBoT9pzjl3TWEwR0EKg/8VbLIVGpHNOULT1tHB+Z52pHdoACA 8QJLEb+U1iILqnD+2GBU+PjU2pV5vnbVFMvFYyn8Ujqz15B3CipOOGCQFeKJejd/y3mW ZuuA==
MIME-Version 1.0
X-Received by 10.50.66.197 with SMTP id h5mr9984544igt.34.1407543204762; Fri, 08 Aug 2014 17:13:24 -0700 (PDT)
In-Reply-To <CALvWhxvx0HUQmMKTw=XCYac7E8ZsivM_S=3E-FAHfUpJT-Ge3g@mail.gmail.com>
References <CANhUTb9tEnT=uTMhdA+Fd2zJTMauo1BWkX2dgcE0dG_H5arx9Q@mail.gmail.com> <CALvWhxtWyQw08TBVOTDhfFjm0=PP19QY3Yv-v74Q2T=ndyW91g@mail.gmail.com> <CAPTjJmq=dydhFEooRHqG2UaHTREjJSyqk9McuDYhc8PRjSzTgA@mail.gmail.com> <CALvWhxvx0HUQmMKTw=XCYac7E8ZsivM_S=3E-FAHfUpJT-Ge3g@mail.gmail.com>
Date Sat, 9 Aug 2014 10:13:24 +1000
Subject Re: Newbie needing some help
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12773.1407543213.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407543213 news.xs4all.nl 2927 [2001:888:2000:d::a6]:53308
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75917

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web