pickle and module package
Jeffrey Kunce
kuncej at mail.conservation.state.mo.us
Tue May 18 10:34:55 EDT 1999
>As you already noted: the two modules could in fact be
>two different libs and it is not just pickle that treats
>them differently but also the sys.modules dictionary.
The plot thickens...
>you can add init code to the modules that checks whether they have
>already been imported by e.g. placing an entry into a dictionary
>sys.module_registry.
not a bad idea - except you shouldn't *have* to do that.
I'm running into problems where I have a deep hierarchy of
packages. Maybe I'm taking the package thing too far, but I've
tried to put all my production code into one big hierarchy something like:
mycompany.applications.mysystem.mysubsystem.mymodule
mycompany.lib.mylibcategory.mymodule
The problem happens when I pull some code out into a separate directory
to do some maintenance or make some improvements. I do my imports
like this:
try: import mymodule
except ImportError: from mycompany.lib.mylibcategory import mymodule
That way, all the modules I'm working on are will be found
first in the local directory - any others will be pulled from the standard
package hierarchy. This scheme has been working well for me, except for
pickled data.
It seems to me that modules may have "relative package names" in some
situations, but must have "absolute package names" in other situations.
I would prefer that this be consistent, but I'd at least like to see it
documented.
--Jeff
More information about the Python-list
mailing list