Need help fixing this error please:NameError: global name is not defined

Chris Angelico rosuav at gmail.com
Thu Sep 6 07:53:57 EDT 2012


On Thu, Sep 6, 2012 at 9:37 PM, shaun <shaun.wiseman91 at gmail.com> wrote:
> class StringCall:
>         results=[]
>         def databasebatchcall(self,termid, batchid):
>                 con = cx_Oracle.connect('user/user123 at odb4.dcc.company.ie/ODB4TEST.COMPANY.IE')
>                 cur = con.cursor()
>                 cur.execute("SELECT * from name)
>                 results = cur.fetchall()

This actually never sets 'results', which is a class variable. You
should probably be using 'self.results' here; Python does not include
class/instance members in scope automatically.

Try using 'self.' for everything that you need to be maintained as
state, and see if that solves your problem.

But this looks to me like a case where you may not really even need a
class at all.

ChrisA



More information about the Python-list mailing list