I'm trying to define a class RecurringInterval which uses the rrule class from dateutil.rrule through composition, and in addition has the attribute period which by default is None. I've tried to initialize it in this way:
class RecurringInterval(object):
def __init__(self, *args, period=None, **kwargs):
self.period = period
self.rrule = dateutil.rrule.rrule(*args, **kwargs)
recurring_interval = RecurringInterval(dateutil.rrule.DAILY, count=1)
However, I get a SyntaxError:
File "/home/kurt/dev/scratch/Furion_scheduler/recurring_interval.py", line 7
def __init__(self, *args, period=None, **kwargs):
^
SyntaxError: invalid syntax
As I understand it, positional arguments should come before keyword arguments, so this is how I would expect the syntax to be; how would I correct it? (From https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists this is not yet clear to me).
I tried bringing period=None forward, like so:
class RecurringInterval(object):
def __init__(self, period=None, *args, **kwargs):
self.period = period
self.rrule = dateutil.rrule.rrule(*args, **kwargs)
but this gives rise to a TypeError:
Traceback (most recent call last):
File "/home/kurt/dev/scratch/Furion_scheduler/recurring_interval.py", line 9, in <module>
recurring_interval = RecurringInterval(dateutil.rrule.DAILY, count=1)
File "/home/kurt/dev/scratch/Furion_scheduler/recurring_interval.py", line 7, in __init__
self.rrule = dateutil.rrule.rrule(*args, **kwargs)
TypeError: __init__() takes at least 2 arguments (2 given)
How can I initialize the RecurringInterval in the intended fashion?
__init__as__init__(self, period=None, *args, **kwargs), I tried running the code in Python 3, but I then getTypeError: __init__() missing 1 required positional argument: 'freq'.