[英]python: Selecting from mysql table
I am trying to select the region of a country from a mysql table using Python. 我正在尝试使用Python从mysql表中选择一个国家的地区。 However, when I write the following code: 但是,当我编写以下代码时:
cur.execute("select region from player_list where country = %" % (country))
I get the following error message: 我收到以下错误消息:
ValueError: incomplete format ValueError:格式不完整
I am not 100% certain what the proper format is for getting this information from a mysql table using mysql.connector. 我不确定100%使用mysql.connector从mysql表中获取此信息的正确格式是什么。
您可以这样尝试:
cur.execute("select region from player_list where country = {0}".format(country))
这可能取决于您的ORM,但对我来说,正确的语法是:
cur.execute("select region from player_list where country = %s", [country])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.