[Python-Dev] Package ambiguities
Ka-Ping Yee
Ka-Ping Yee <pingster@ilm.com>
Wed, 7 Jun 2000 14:05:26 -0700 (PDT)
On Wed, 7 Jun 2000, Andy Robinson wrote:
> We hit some very weird behaviour recently while setting up a package
> hierarchy. Robin Becker managed to distil this into a simple example.
> Can anyone shed any light on what is happening below? Is Python
> behaving as it should?
It looks to me like you have two "parent" modules.
When you run "test.py" directly from the command line, the
first "from parent import *" imports parent.py as module "parent".
But subsequently parent.py is imported again as module "A.parent".
Similarly, you have two "Examiner" classes. In run0() you
get Examiner from __main__, which contains the Parent class
from module "parent". In run1() you get Examiner from A.test,
which contains the Parent class imported from module "A.parent".
If you insert
print 'in module', __name__, 'parent is', repr(Parent)
at the beginning of the examine() method, it should make things
clear.
The solution is to avoid directly running scripts that are
inside packages; the confusion is produced by the fact that
you're running "test.py" from within the A/ directory.
-- ?!ng