Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'output': 0.04; 'formatting': 0.07; 'method,': 0.07; 'undefined': 0.07; 'subject:help': 0.07; 'garbage': 0.09; 'name)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'throw': 0.09; 'thrown': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'unpacking': 0.09; 'def': 0.10; 'subject:error': 0.11; 'subject:not': 0.11; 'language': 0.14; 'collected.': 0.16; 'data...': 0.16; 'ends,': 0.16; 'finishes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'record,': 0.16; 'row': 0.16; 'thu,': 0.17; 'skip:" 40': 0.20; 'names.': 0.22; 'skip:c 70': 0.22; 'work,': 0.22; "i'd": 0.22; 'second': 0.24; 'pass': 0.25; 'skip:" 20': 0.26; 'skip:" 50': 0.27; 'subject:please': 0.27; 'header:X-Complaints-To:1': 0.28; 'record': 0.28; 'class': 0.29; 'classes': 0.30; 'filled': 0.30; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; "you've": 0.61; 'subject:Need': 0.61; 'first': 0.61; 'repeat': 0.62; 'results': 0.65; 'study': 0.66; 'subject::': 0.83; 'subject:this': 0.84; 'disappear': 0.84; 'here...': 0.84; 'locals': 0.84; 'dennis': 0.91; 'received:108': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Need help fixing this error please:NameError: global name is not defined Date: Thu, 06 Sep 2012 17:16:58 -0400 Organization: > Bestiaria Support Staff < References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-223-184.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346966229 news.xs4all.nl 6917 [2001:888:2000:d::a6]:46115 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28642 On Thu, 6 Sep 2012 04:37:04 -0700 (PDT), shaun declaimed the following in gmane.comp.python.general: > > class StringCall: > results=[] > def databasebatchcall(self,termid, batchid): What are termid and batchid -- you pass them into the method, and NEVER USE THEM! > con = cx_Oracle.connect('user/user123@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') > cur = con.cursor() > cur.execute("SELECT * from name) con and cur are locals to this function/method > results = cur.fetchall() > results is also a local... All three disappear when the method returns I suspect you need to study the language reference regarding classes and function/methods, argument passing, and the use of "self" > > def fetchbatchdata(self,results): > > for row in results: > mer = row[0].ljust(25, ' ') > mercity = row[1].ljust(13, ' ') > mertype = row[2] > merloc = row[3] > mercount = row[4] > mersec = row[5] > acq = row[6] > btime = row[7].strftime('%d%m') > bmerch = str(row[8]).rjust(12, '0') > termcur = row[9] > acqbank = str(row[10]).rjust(24, '0') > termtype = row[11] > termsoftver = row[12] > merbatch = str(row[13]).rjust(3, '0') > reccount = str(row[14]).rjust(9, '0') > amounttotal = str(row[15]).rjust(16, '0') > cashback = str(row[16]).rjust(16, '0') > deposit = str(row[17]).rjust(16, '0') > I'd reserve all the formatting for when you need to output the data; that would permit using tuple unpacking (mer, mercity, mertype, ... cashback, deposit) = row But note that after you've filled all those names with the first record -- you throw the first record away with the data from the second record, and repeat for each record... When the loop ends, all those names only reference the last record's data... AND then the method finishes and all those names are garbage collected. > def createbatchstrings(self): > BatchHeaderPacket = "\x01000\x0251.520%s00000%s000006060001%s%s%s%s0003 \x03" % (btime, bmerch, termcur, acqbank, termtype, termsoftver); > ParameterPacket = "\x01001\x0251.5300000401%s%sIE%s%s%s00000%s%s0%s \x03" % (mer, mercity, mertype, merloc, termid, mercount, mersec, acq); > TrailerPacket = "\x01003\x0251.550%s00%s%s%s%s%s00000000000\x03" % (btime, merbatch, reccount, amounttotal, cashback, deposit); > cur.close() > All the xxxxPacket names are local and will be thrown away after the method returns... And cur, mer, mercity, etc. are UNDEFINED locals here... > def returnbatchheader(self): > return BatchHeaderPacket > def returnparameterpacket(self): > return ParameterPacket > def returntrailerpacket(self): > return TrailerPacket > None of these "return xxxx" will work, since the "xxxx" are all undefined local names. And these methods are superfluous, why not just have "createBatchStrings" return all three as a tuple. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/