Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'attribute': 0.07; 'bug.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; 'concern,': 0.16; 'objection': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:n 70': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'obviously': 0.18; 'commit': 0.19; 'work,': 0.20; 'seems': 0.21; 'code,': 0.22; 'example': 0.22; 'looks': 0.24; 'source': 0.25; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; '(which': 0.31; 'class': 0.32; 'this.': 0.32; 'checked': 0.32; 'another': 0.32; 'quite': 0.32; 'actual': 0.34; 'noticed': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'connection': 0.35; 'transaction': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'consistent': 0.36; 'possible': 0.36; 'error.': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'places': 0.64; 'here': 0.66; 'answer.': 0.68; 'frank': 0.68; 'jul': 0.74; 'demonstrates': 0.84; 'ethan': 0.84; 'factoring': 0.84; 'furman': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Default scope of variables Date: Wed, 10 Jul 2013 07:54:22 +0200 References: <51d4eb9c$0$29999$c3e8da3$5496439d@news.astraweb.com><51d508ed$0$6512$c3e8da3$5496439d@news.astraweb.com><51d5a504$0$29999$c3e8da3$5496439d@news.astraweb.com> <51DC355E.20606@stoneleaf.us> X-Gmane-NNTP-Posting-Host: 197.87.30.31 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373435673 news.xs4all.nl 15996 [2001:888:2000:d::a6]:55896 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50299 "Ian Kelly" wrote in message news:CALwzidnf3Obe0eNf3xTHLj5a40K8HxVThVEipECQ8+34ZxyLxw@mail.gmail.com... > On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman wrote: >> You could also do it like this: >> >> def updating(self): >> self.transaction_active = True >> return self > > Yes, that would be simpler. I was all set to point out why this > doesn't work, and then I noticed that the location of the > "transaction_active" attribute is not consistent in the original code. > The DbSession class places it on self, and then the example usage > places it on the connection object (which I had based my version on). > Since that seems to be a source of confusion, it demonstrates another > reason why factoring this out is a good thing. You had me worried there for a moment, as that is obviously an error. Then I checked my actual code, and I find that I mis-transcribed it. It actually looks like this - with db_session as conn: db_session.transaction_active = True conn.cur.execute(...) I am still not quite sure what your objection is to this. It feels straightforward to me. Here is one possible answer. Whenever I want to commit a transaction I have to add the extra line. There is a danger that I could mis-spell 'transaction_active', in which case it would not raise an error, but would not commit the transaction, which could be a hard-to-trace bug. Using your approach, if I mis-spelled 'db_session.connect()', it would immediately raise an error. Is that your concern, or are there other issues? Frank