python - can a return value of a function be passed in the where clause -


i have python code displays list of station id , air temperature number of days. in code below have passed dates list. cumbersome coding since have write dates in list. there way wherein can pass return value of function clause. want know how range of values start , end date can passed in query below. following code snippet:

import mysqldb import os,sys import datetime path="c:/python27/" conn = mysqldb.connect (host = "localhost",user = "root", passwd = "cimis",db = "cimis") c = conn.cursor() message = """select stationid,date,airtemperature cimishourly stationid in (2,7) , date in ('2016,01,01','2016,01,04') """ c.execute(message,) result=c.fetchall() row in result:     print(row) conn.commit() c.close() 

yes can substitute return value of function in query. because message string can concatenate other string.

message = """select stationid,date,airtemperature cimishourly stationid in (2,7) , date in (""" + functiontogetdates() + """)"""

the parentheses can formatted in function or in original string chose do.


Comments