2014-10-01 57 views
-1

我正在嘗試使用數字數據var'y'的excel數據,並將其放入我的SQL列'Close'中。TypeError:'str'對象不可調用

import xlrd 
import MySQLdb 

#get excel data 
file_location = "C:/Users/.../.../...xls" 
workbook = xlrd.open_workbook(file_location) 
sheet = workbook.sheet_by_name("Sheet1.1") 
y = sheet.col_values(3, start_rowx=2, end_rowx=31) 

#open connection SQL 
db=MySQLdb.connect(host = "host", 
        user = "user", 
        passwd = "passwd", 
        db = "test") 
cursor = db.cursor() 
cursor.execute("""UPDATE uk SET Close.....""") 

db.commit() 

但是我不確定寫什麼來插入它。

cursor.execute("""UPDATE uk SET Close = %s""", (y,)) 

給出了錯誤:

OperationalError: (1241, 'Operand should contain 1 column(s)') 

感謝您的幫助,也可以提供方向。

回答

2

你忘了2個逗號:

cursor.execute("""UPDATE uk SET Close = %s""", (y,)) 

沒有這些,你正在執行:

"""..."""(y) 

例如試圖像調用函數一樣調用字符串對象。