Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'method.': 0.05; 'socket': 0.05; 'sys': 0.05; 'method,': 0.07; 'subject:help': 0.07; 'python': 0.09; 'literal': 0.09; 'name)': 0.09; 'returns,': 0.09; 'def': 0.10; 'subject:error': 0.11; 'subject:not': 0.11; 'assume': 0.11; '"from': 0.16; 'class:': 0.16; 'compile.': 0.16; 'discarded': 0.16; 'echo': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'pprint': 0.16; 'row': 0.16; 'subject: \n ': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'load': 0.19; 'skip:" 40': 0.20; 'import': 0.21; 'names.': 0.22; 'skip:c 70': 0.22; 'struct': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'separate': 0.27; 'skip:# 10': 0.27; 'skip:" 50': 0.27; 'subject:please': 0.27; 'received:192.168.1.3': 0.29; 'class': 0.29; 'code': 0.31; 'file': 0.32; 'to:addr:python-list': 0.33; 'guys': 0.33; "won't": 0.35; 'something': 0.35; 'method': 0.36; 'client': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'subject:Need': 0.61; 'here': 0.65; 'results': 0.65; 'header :Reply-To:1': 0.68; 'soon': 0.70; 'wish': 0.70; 'reply-to:no real name:2**0': 0.72; 'subject::': 0.83; 'subject:this': 0.84; 'etc,': 0.84; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=W6e6pGqk c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=lR6CHUT36vYA:10 a=AQOAEiZb4DUA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=2lCcAAb-dOIA:10 a=IgWObzIyz-FmHKcOvh0A:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Thu, 06 Sep 2012 13:08:35 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Need help fixing this error please:NameError: global name is not defined References: <149e9472-ec31-4b74-9f20-d4945a9fb678@googlegroups.com> <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> In-Reply-To: <42718e31-d77b-4c8a-ae48-1dae0a780585@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346933317 news.xs4all.nl 6930 [2001:888:2000:d::a6]:39261 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28581 On 06/09/2012 12:37, shaun wrote: > Sorry guys here is the full code for the class: > > #!/usr/bin/python > # Echo client program > import cx_Oracle > import socket > import pprint > from struct import * > import sys > from binascii import * Don't use "from something import *". It'll import a whole load of names. Import only those names you wish to use. > import time > import datetime > > > class StringCall: > results=[] > def databasebatchcall(self,termid, batchid): > con = cx_Oracle.connect('user/user123@odb4.dcc.company.ie/ODB4TEST.COMPANY.IE') > cur = con.cursor() > cur.execute("SELECT * from name) That line has an unterminated string literal (missing quote). That means that this file won't compile. > results = cur.fetchall() As you're binding to "results" in the method, Python will assume that that name is local to the method. The results will be discarded as soon as the method returns, which it does right after. > > > 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') All of the names "mer", "mercity", etc, will be local to this method. > > 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() Where do the names "btime", "bmerch", etc, come from? They are certainly not the same as those in "fetchbatchdata" because this is a separate method. > > def returnbatchheader(self): > return BatchHeaderPacket > def returnparameterpacket(self): > return ParameterPacket > def returntrailerpacket(self): > return TrailerPacket >