【问题标题】:function pointer with parameters in python?python中带参数的函数指针?
【发布时间】:2012-05-27 01:38:56
【问题描述】:

我正在阅读来自 pythonCron-job 的文档(示例 1):

from apscheduler.scheduler import Scheduler

# Start the scheduler
sched = Scheduler()
sched.start()

def job_function():
    print "Hello World"

# Schedules job_function to be run on the third Friday
# of June, July, August, November and December at 00:00, 01:00, 02:00 and 03:00
sched.add_cron_job(job_function, month='6-8,11-12', day='3rd fri', hour='0-3') 

是否可以将参数添加到 job_function 以及如何将它们传递给 add_cron_job

【问题讨论】:

    标签: python api function-pointers cron-task


    【解决方案1】:

    使用args 关键字参数:

    # call job_function with arguments 'hello' and 'world'
    sched.add_cron_job(job_function, args=('hello', 'world'), month='1', day='1st fri', hour='0') 
    

    the definition of add_cron_job

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 1970-01-01
      • 2018-08-25
      • 2019-09-16
      • 2019-11-30
      相关资源
      最近更新 更多