2013-02-21 65 views
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) 

任何想法?

+1

其中*是*行定義? – Johnsyweb 2013-02-21 22:01:02

+0

condition = row ['where'] ???我發誓這是我的第一個Python應用程序... – engr007 2013-02-21 22:03:32

+0

@ Martijn明白了。我仍然在編輯器中格式化您的代碼,以便我可以看到它! – Johnsyweb 2013-02-21 22:04:24

回答

1

您將您的函數參數命名爲key,而不是row。改爲使用key['where'],或將參數重命名爲row