[Zope] Interesting mxDateTime problem (and solution)
Malcolm Tredinnick
malcolm@commsecure.com.au
Thu, 4 May 2000 12:35:40 +1000
I've just spent most of the morning beating my head against this problem, so I
thought I'd post something here in case others hit the same issues:
I use Marc Lemburg's mxDateTime package extensively in my Python programs and
was trying to incorporate some things using it into Zope. Unfortunately, it is
apparently not possible to use it "straight out of the box" with Zope because
of problems with the import path.
To make DateTime work under Zope, you have to rename the directory to
something *other* than DateTime (I'm calling it DateTm, for example). If you
have lots of references to DateTime scattered around in your code (as I do),
the simplest thing seems to be to change any 'import DateTime' lines to:
import DateTm
DateTime = DateTm
It's ugly, but it works. :-)
The reason for this is because when you run 'import DateTime', the __init__.py
method tries to do 'from DateTime import *', expecting to import things from
DateTime/DateTime.py. However, it appears that the python interpreter starts
from the beginning of the import path and looks for the DateTime module again
and stumbles across the directory, rather than DateTime.py. Since this doesn't
occur outside of Zope, it is a combination of a strange path setup (or
environment, I'm not sure which) under Zope and some unlucky (but usually
quite ok) naming (DateTime directory and DateTime.py inside that directory).
Maybe this will save somebody else some hours. :-)
Cheers,
Malcolm
--
Malcolm Tredinnick ph: +61 2 9440 9885
CommSecure Pty Ltd mobile: 0409 663 876
email: malcolm@commsecure.com.au