Mailing List Archive

package.module != module
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!
package.module != module [ In reply to ]
>>>>> "QD" == Quinn Dunkan <quinn@necro.ugcs.caltech.edu> writes:

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

Feature.

If you're running a program "publish" from a directory called
"package" that does not make this directory into a package. Hence,
importing "sister" just imports it from the "current directory"
whereas importing "package.sister" initializes the package and then
imports sister from it.

Moral is: don't put "programs" into packages, or always import fully
qualified module names.

I had the same problem before:
http://www.dejanews.com/[ST_rn=ap]/getdoc.xp?AN=437913465

Regards,


--
===== R.Hooft@EuroMail.net http://www.xs4all.nl/~hooft/rob/ =====
===== R&D, Nonius BV, Delft http://www.nonius.nl/ =====
===== PGPid 0xFA19277D ========================== Use Linux! =========