Python .format() 解析 ':' 字符
Python .format() parse ':' character
我有以下代码,sql 在数据库中工作正常,但在 python 中(使用 .format()
)给出错误 ': syntax error at or near ":"
那么我该如何解析 :
字符?
code = 'ABC:2674.45'
job = '103'
# connect to database
conn = connect()
# select query
query = """
SELECT job, code
FROM schema.table
WHERE job = {} and code = {}
order by code, job
""".format(job, code)
pd.read_sql_query(query, conn)
这解决了问题,让我知道是否可以改进
df = pd.read_sql_query("SELECT job, code FROM schema.table WHERE job = %s and code = %s order by code, job", con=conn, params=(pgram_job, sitecode))
我有以下代码,sql 在数据库中工作正常,但在 python 中(使用 .format()
)给出错误 ': syntax error at or near ":"
那么我该如何解析 :
字符?
code = 'ABC:2674.45'
job = '103'
# connect to database
conn = connect()
# select query
query = """
SELECT job, code
FROM schema.table
WHERE job = {} and code = {}
order by code, job
""".format(job, code)
pd.read_sql_query(query, conn)
这解决了问题,让我知道是否可以改进
df = pd.read_sql_query("SELECT job, code FROM schema.table WHERE job = %s and code = %s order by code, job", con=conn, params=(pgram_job, sitecode))