【发布时间】:2019-04-18 21:10:36
【问题描述】:
我正在尝试在 python 中构建一个函数,该函数根据用户传递的参数返回输出。
以下是基本功能:
def report():
db_conn
dwh_cursor = conn.cursor() # set DB Cursor
## Query
dwh_cursor.execute(sql.SQL("""select name,class,team,position from students"""))
上述函数在执行时工作正常。我在这里要修改的是当我传递一个带有值的参数时,只有该列应该在函数的输出中返回。例如,在下面的函数中,我只传递了两个参数,即名称和类,我希望输出中只有这两个值,如下所示:
def report(name,class,team,position):
db_conn
dwh_cursor = conn.cursor() # set DB Cursor
## Query
dwh_cursor.execute(sql.SQL("""select name,class,team,position from students"""))
report("Scott","High_School","","")
Expected query to be executed:
## Query
dwh_cursor.execute(sql.SQL("""select (%s),(%s) from students"""), (name,class))
谁能指导我如何获得这个指定的输出?
【问题讨论】:
标签: python python-3.x function arguments