【发布时间】:2018-05-22 14:18:34
【问题描述】:
我使用一个配置文件(type .ini)来保存我的 SQL 查询,然后我通过它的键得到一个查询。一切正常,直到创建带有参数的查询,例如:
;the ini file
product_by_cat = select * from products where cat =%s
我用:
config = configparser.ConfigParser()
args= ('cat1')
config.read(path_to_ini_file)
query= config.get(section_where_are_stored_thequeries,key_of_the_query)
complete_query= query%args
我得到了错误:
TypeError:字符串格式化期间并非所有参数都转换
所以它尝试在从 ini 文件中检索值时格式化字符串。 我的问题的任何建议。
【问题讨论】:
标签: sql python-3.x ini