Hi,

has a function weekdaytask. It needs five parameters as stated in the scheduler.py. weekdays and timeonday I figured out. You tell me what is name and action, args=None, kw=None ?

BRgds,

kNish
=====================================================
class WeekdayTask(DayTaskRescheduler, Task):
"""A task that is called at specific days in a week (1-7), at a fixed time on the day."""
def __init__(self, name, weekdays, timeonday, action, args=None, kw=None):
if type(timeonday) not in (list,tuple) or len(timeonday) != 2:
raise TypeError("timeonday must be a 2-tuple (hour,minute)")
if type(weekdays) not in (list,tuple):
raise TypeError("weekdays must be a sequence of weekday numbers 1-7 (1 is Monday)")
DayTaskRescheduler.__init__(self, timeonday)
Task.__init__(self, name, action, args, kw)
self.days=weekdays

def execute(self):
# This is called every day, at the correct time. We only need to
# check if we should run this task today (this day of the week).
weekday=time.localtime().tm_wday+1
if weekday in self.days:
self.action(*self.args, **)
========================================================

Dani AI

Generated

— The parameters are, in order: name, weekdays, timeonday, action, args=None, kw=None. In plain terms: name is just an identifier (string) for the task; weekdays is a sequence of weekday numbers where 1 = Monday and 7 = Sunday; timeonday must be a 2-tuple like (hour, minute) (the class only checks that it is a 2‑tuple, so supply sensible values such as 0–23 for hour and 0–59 for minute); action is the callable that will be executed; args should be a tuple of positional arguments to pass to action; kw should be a dictionary of keyword arguments for action.

Common pitfalls to avoid: do not swap the timeonday and action positions (the constructor expects timeonday before action), and do not try to pass the action’s keyword arguments directly to WeekdayTask as normal kwargs — they must be bundled into the kw dict. If the action takes one positional argument, use a single-element tuple like (value,) (the trailing comma is required). If you prefer, bind arguments ahead of time with functools.partial and pass a no‑arg callable as action.

A simple example (showing correct ordering and types):

def send_report(timestamp, verbose=False):
    # do work

task = WeekdayTask(
    name="weekly-report",
    weekdays=(7,),            # Sunday
    timeonday=(2, 15),        # 02:15
    action=send_report,
    args=(time.time(),),      # positional args
    kw={'verbose': True}      # keyword args
)

was right to say action is the function and args/kw supply parameters, but be careful: the constructor does not accept arbitrary keyword parameters for the action — they go inside kw. If you hit a TypeError when the task runs, confirm that args is a tuple and kw is a dict (or use partial to avoid passing them).

I don't have that module, but it looks like action is a function that is called; name would probably be a string name for the display; args would be a tuple of args to supply to the action, and kw would be a dictionary of keyword arguments to supply.

So if I had

myMondayChore(time, num_kids=2, day_care = False)

then I would create a scheduling object like this:

mytask = WeekdayTask("Monday", myMondayChore, 3, num_kids=2, day_care=False)

The three will be packed into *args; the num_kids=2 and day_care=False will be packed into **kw.

Hope that helps,
Jeff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.