gpt4 book ai didi

python - ValueError 不支持的格式字符 'd' 与 psycopg2

转载 作者:行者123 更新时间:2023-11-28 20:48:12 25 4
gpt4 key购买 nike

我有这样的代码:

print "company_id = %d" % company_id
...
db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);", (company_id, name[0], name[1], type))

我得到以下输出:

company_id = 1
Traceback (most recent call last):
...
File "./GetPeople.py", line 125, in insertPerson
db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);",

为什么它可以打印出第一行,但在调用 db.cursor.execute() 时却报错?

最佳答案

%s 占位符周围的单引号不正确且未使用 %d as per the docs .变化

db.cursor.execute("insert into person (company_id, first, last, type) values (%d, '%s', '%s', %d);", (company_id, name[0], name[1], type))

db.cursor.execute("insert into person (company_id, first, last, type) values (%s, %s, %s, %s);", (company_id, name[0], name[1], type))

关于python - ValueError 不支持的格式字符 'd' 与 psycopg2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17409829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com