Author pmoore
Recipients
Date 2005-01-29.22:02:22
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=113328

Essentially, because pkg\__init__.py is loaded into
sys.modules under *two* names. First, as pkg (as part of the
process of importing pkg.test) and then as pkg.__init__
(explicitly in pkg\test.py). As the source is loaded twice,
the print is executed twice.

While subtle, this is not a bug.

To demonstrate:

>>> import sys
>>> orig = set(sys.modules.keys())
>>> import pkg.test
init
init
test
>>> set(sys.modules.keys()) - orig
set(['pkg.test', 'pkg', 'pkg.__init__'])

You see, both pkg and pkg.__init__ are separately in
sys.modules (even though they refer to the same file).

In essence, it is incorrect to import __init__ directly -
always import the package. If test.py had said "import pkg",
you wouldn't have seen this behaviour, but nothing else
would have changed.
History
Date User Action Args
2007-08-23 14:22:46adminlinkissue977250 messages
2007-08-23 14:22:46admincreate