函数指针与python中的参数?

时间:2012-05-27 01:38:56

标签: python api function-pointers cron-task

我正在阅读python Cron-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

1 个答案:

答案 0 :(得分:2)

使用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