簡體   English   中英

python:從mysql表中選擇

[英]python: Selecting from mysql table

我正在嘗試使用Python從mysql表中選擇一個國家的地區。 但是,當我編寫以下代碼時:

cur.execute("select region from player_list where country = %" % (country))

我收到以下錯誤消息:

ValueError:格式不完整

我不確定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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM