函數中執行查詢,功能:類型錯誤字符串指數必須爲整數時pyodbc
def getUserList(connection):
li = []
cur = connection.cursor()
query = 'select username, password, firstname, lastname, description, phone,'+
'email, isAdmin, isAutoBoot from users_tbl'
cur.execute(query)
for usr, pwd, fn, ln, des, ph, em, ad, au in cur.fetchall():
temp = User(usr, pwd, fn, ln, des, ph, em, ad, au)
cur.close()
#con.close()
return li
當我導入模塊和運行該功能,遇到類型錯誤:
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
import_user.getUserList(s_con)
File "c:/python27/mymodule\import_user.py", line 12, in getUserList
cur.execute(query)
TypeError: string indices must be integers
但是,如果我複製並運行這些線在Python IDLE的,它運行良好,沒有錯誤時,執行光標。它發生在我傳遞pyodbc或sqlite連接作爲輸入參數時。
感謝
我得到以'+'結尾的行上的SyntaxError。 –