0

这是我的代码......我得到

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

代码:

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)

有任何想法吗?

4

1 回答 1

1

您将函数参数命名为key,而不是row。改为使用key['where'],或将函数的参数重命名为row.

于 2013-02-21T22:02:47.353 回答