Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29805 > unrolled thread
| Started by | tinnews@isbd.co.uk |
|---|---|
| First post | 2012-09-23 11:24 +0100 |
| Last post | 2012-09-23 16:26 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
A dateutil error has appeared, due to updates? How to fix? tinnews@isbd.co.uk - 2012-09-23 11:24 +0100
Re: A dateutil error has appeared, due to updates? How to fix? Peter Otten <__peter__@web.de> - 2012-09-23 13:38 +0200
Re: A dateutil error has appeared, due to updates? How to fix? tinnews@isbd.co.uk - 2012-09-23 16:26 +0100
| From | tinnews@isbd.co.uk |
|---|---|
| Date | 2012-09-23 11:24 +0100 |
| Subject | A dateutil error has appeared, due to updates? How to fix? |
| Message-ID | <vj43j9-df9.ln1@chris.zbmc.eu> |
I have a python script which uses the dateutil module with the
following:-
import sys
import datetime
import icalendar
from dateutil.relativedelta import relativedelta
The section of code which uses relativedelta is as follows:-
#
#
# If the event is a repeating event with a start date in the
# past then we add the repeat interval until we find the next
# occurrence
#
if eventDate < datetime.date.today():
if event.has_key('RRULE'):
freq = event.decoded('RRULE')['FREQ'][0]
if event.decoded('RRULE').has_key('INTERVAL'):
interval = event.decoded('RRULE')['INTERVAL'][0]
else:
interval = 1;
if 'WEEKLY' == freq:
delta = relativedelta(weeks=+interval)
if 'MONTHLY' == freq:
delta = relativedelta(months=+interval)
if 'YEARLY' == freq:
delta = relativedelta(years=+interval)
while eventDate < datetime.date.today():
eventDate += delta
else:
continue # if it's a non-repeating event in the past
It used to work and all I have done meanwhile is to update my xubuntu
system as fixes are released. I'm now getting the error:-
Traceback (most recent call last):
File "/home/chris/bin/calics.py", line 62, in <module>
eventDate += delta
File "/usr/lib/python2.7/dist-packages/dateutil/relativedelta.py", line 261, in __radd__
day = min(calendar.monthrange(year, month)[1],
AttributeError: 'module' object has no attribute 'monthrange'
Have I lost a module somewhere in the updates or has something in
python changed such that my code no longer works as it used to?
Can anyone help diagnose this please.
--
Chris Green
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2012-09-23 13:38 +0200 |
| Message-ID | <mailman.1116.1348400237.27098.python-list@python.org> |
| In reply to | #29805 |
tinnews@isbd.co.uk wrote:
> I have a python script which uses the dateutil module with the
> following:-
>
> import sys
> import datetime
> import icalendar
> from dateutil.relativedelta import relativedelta
>
> The section of code which uses relativedelta is as follows:-
>
> #
> #
> # If the event is a repeating event with a start date in the
> # past then we add the repeat interval until we find the next
> # occurrence
> #
> if eventDate < datetime.date.today():
> if event.has_key('RRULE'):
> freq = event.decoded('RRULE')['FREQ'][0]
> if event.decoded('RRULE').has_key('INTERVAL'):
> interval = event.decoded('RRULE')['INTERVAL'][0]
> else:
> interval = 1;
> if 'WEEKLY' == freq:
> delta = relativedelta(weeks=+interval)
> if 'MONTHLY' == freq:
> delta = relativedelta(months=+interval)
> if 'YEARLY' == freq:
> delta = relativedelta(years=+interval)
> while eventDate < datetime.date.today():
> eventDate += delta
> else:
> continue # if it's a non-repeating event in the
> past
>
>
> It used to work and all I have done meanwhile is to update my xubuntu
> system as fixes are released. I'm now getting the error:-
>
> Traceback (most recent call last):
> File "/home/chris/bin/calics.py", line 62, in <module>
> eventDate += delta
> File "/usr/lib/python2.7/dist-packages/dateutil/relativedelta.py",
> line 261, in __radd__
> day = min(calendar.monthrange(year, month)[1],
> AttributeError: 'module' object has no attribute 'monthrange'
>
> Have I lost a module somewhere in the updates or has something in
> python changed such that my code no longer works as it used to?
>
> Can anyone help diagnose this please.
You probably have a file named calendar.py in your working directory:
$ python -c 'from dateutil.relativedelta import calendar; print
calendar.__file__'
/usr/lib/python2.7/calendar.pyc
$ touch calendar.py
$ python -c 'from dateutil.relativedelta import calendar; print
calendar.__file__'
calendar.py
Rename calendar.py in your working directory (and don't forget to delete the
corresponding calendar.pyc) -- and dateutil should work again.
[toc] | [prev] | [next] | [standalone]
| From | tinnews@isbd.co.uk |
|---|---|
| Date | 2012-09-23 16:26 +0100 |
| Message-ID | <3am3j9-cfc.ln1@chris.zbmc.eu> |
| In reply to | #29808 |
Peter Otten <__peter__@web.de> wrote: > tinnews@isbd.co.uk wrote: > [snip description of problem] > > Have I lost a module somewhere in the updates or has something in > > python changed such that my code no longer works as it used to? > > > > Can anyone help diagnose this please. > > You probably have a file named calendar.py in your working directory: > > $ python -c 'from dateutil.relativedelta import calendar; print > calendar.__file__' > /usr/lib/python2.7/calendar.pyc > $ touch calendar.py > $ python -c 'from dateutil.relativedelta import calendar; print > calendar.__file__' > calendar.py > > Rename calendar.py in your working directory (and don't forget to delete the > corresponding calendar.pyc) -- and dateutil should work again. > Brilliant, you're absolutely right! Thank you! :-) I'd written calendar.py doing something else entirely. I must remember not to use such 'obvious' names for things! -- Chris Green
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web