简体   繁体   中英

Passing Parameters to SQLDF in Python

I'm trying to pass parameters through sqldf in python:

id = '001F5'
q = """select * from df where id= %id; """
test = sqldf(q, globals())

I've tried many things eg +id, "+id;"" and %id etc and nothing works, is it possible to do this at all?

Many Thanks

Try:

id = "'001F5'"
q = "select * from df where id=" + id + ";"
test = sqldf(q, globals())

Or you can try:

id = "'001F5'"
q = "select * from df where id={0};".format(id)
test = sqldf(q, globals())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM