package.module != module

Quinn Dunkan quinn at necro.ugcs.caltech.edu
Sat Apr 24 02:42:59 EDT 1999


I have discovered that apparently python's mechanism for discovering if a
module has already been imported fails when you import a "fully qualified"
package previously imported as a sister.  i.e.:

client.py ("import package.sister")
package/
	__init__.py
	sister.py ("class B: pass")
	publish.py ("""
import sys
sys.path.append('..')
import sister, client
print repr(sister.B), repr(client.package.sister.B)
print sys.modules.keys()
""")

We find that sister.B and client.package.sister.B are different classes.  The
reason why appears to be sys.modules: we have both 'package.sister' and
'sister' imported as seperate modules.

I get this convoluted structure all the time in ZPublisher (Zope), and when I
want to talk about a class defined in a package from a module run by that
package, nothing works because the package has different versions of the same
classes I'm talking about in my modules.  You can't catch exceptions defined
in the package and thrown from a client module.

Feature?  Quirk?  Workaround?  Help!  :)

thanks!




More information about the Python-list mailing list