engr007
engr007

Reputation: 51

Global name 'row' is not defined

Here's my code...I am getting

    .format(table_name=self._table, condition=row['where']))
NameError: global name 'row' is not defined

Code:

def retrieveSmCityCust(self, key):
    cursor = self._db.execute('SELECT CONTRACTS.CUSTOMER_NAME, CONTRACTS.CUSTOMER.CITY, CITIES.POPULATION FROM CONTRACTS JOIN CITIES ON CONTRACTS.CUSTOMER_CITY = CITIES.IDENT where {condition}'.format(table_name=self._table, condition=row['where']))
    return dict(cursor.fetchall())

db = database(filename = 'insurance.sqlite')

db.retrieveSmCityCust({'where': 'CITIES.POPULATION <=500000'})
    for row in db:
        print(row)

Any ideas?

Upvotes: 0

Views: 5589

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124828

You named your function parameter key, not row. Use key['where'] instead, or rename the parameter to the function to row.

Upvotes: 1

Related Questions