Kurt Peek Kurt Peek - 11 days ago 5
Python Question

How to import the dateutil.rrule module in Python

Following the rrule examples, I've noticed I can import the

rrule
object in this fashion:

from dateutil.rrule import *
my_rrule = rrule(DAILY, count=5)
print(list(my_rrule))


which prints the expected output

[datetime.datetime(2016, 11, 23, 16, 55, 30), datetime.datetime(2016, 11, 24, 16, 55, 30), datetime.datetime(2016, 11, 25, 16, 55, 30), datetime.datetime(2016, 11, 26, 16, 55, 30), datetime.datetime(2016, 11, 27, 16, 55, 30)]


However, I like to maintain references to the module, so instead I'm trying to import and use it like this:

import dateutil.rrule
my_rrule = dateutil.rrule.rrule(DAILY, count=5)


However, this leads to a
NameError
:

Traceback (most recent call last):
File "/home/kurt/dev/scratch/Furion_scheduler/recurring_interval.py", line 18, in <module>
my_rrule = dateutil.rrule.rrule(DAILY, count=5)
NameError: name 'DAILY' is not defined


What is going wrong here?

Answer

Try from dateutil.rrule import rrule, DAILY.

Comments