我這是爲了查詢數據庫如下功能:如何引用函數參數字符串中的
def raw_disc(make):
data_make = pd.DataFrame(disc.queryRedshift(
"""select D.model_slug,
D.cap_engine_id,
D.dealership_id,
D.cash_percentage,
D.cash_post_discount_amount as cash_post
from quotes_site.discounts D join quotes_site.dealerships DLR
on D.dealership_id = DLR.id
where DLR.archived <> 't'
and DLR.suspended <> 't',
-> and DLR.make = "make"
group by 1,2,3,4,5"""))
return data_make
因爲查詢是三重引號內我不能添加包含在一個字符串參數做成where子句中DLR.make = "make"
至於我記得在CI會做類似「%s」的,$ d(記不清了)有沒有在python
任何建議或資源以類似的方式將不勝感激
http://stackoverflow.com/questions/35974056/string-substitution-in-python-3 – Bahrom