I need help figuring out how to fix my code. Every time I run the code its traceback is to this part of it. My code is Unbound Local Error for 'result'.

Please see code below:

def Level1(self):
        sql = "SELECT easyhint, gps, qrcode FROM gamedb WHERE quad = 1 ORDER BY RANDOM () LIMIT 1;"

        try:
            cursor.execute(sql)
            result = cursor.fetchmany(size = 7)
        except Exception, e:
            print e

        for row in result:
            while 'easyhint' < 8:
                if 'gps' in row and 'number' in self.person:
                    return row.easyhint.itervalues()
                else:
                    return 0

Any help or suggestions are welcomed.

Any help or suggestions are welcomed.

Declare 'result' outside of the try/except block:

result = []
try:
    cursor.execute(sql)
    result = cursor.fetchmany(size = 7)
except Exception, e:
    print e
for row in result:
    etc...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.