繁体   English   中英

TypeError:“ str”对象不可调用

[英]TypeError: 'str' object is not callable

我正在尝试将excel数据(即数值数据var'y')放入我的SQL列“ Close”中。

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个逗号:

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

没有这些,您将执行:

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

例如,尝试像对待函数一样调用字符串对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM