을에서 함수 내에서 쿼리를 실행해야합니다, 기능은 다음과 같습니다형식 오류 문자열 인덱스는 정수 때 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
및 파이썬 IDLE에서 이러한 라인의 각 실행, 그것을 잘 실행 오류 때 커서를 실행하지 않습니다. 그것은 입력 매개 변수로 pyodbc 또는 sqlite 연결을 전달할 때 발생합니다.
감사
'+'로 끝나는 라인에서 SyntaxError를 얻습니다. –