If I understand correctly what you mean byt a "package-module" then
__init__.py is exactly what you are looking for.
Many packages are built with an empty __init__.py because they are
intended mostly to build a tree-like set of namespaces, but __init__.py
*is* run when the package is imported, and its namespace is bound to the
name of the package within the importing program. So if you have code
you want to run when the package is imported, put it there.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
No. If you do
from sys import modules
print(modules.keys())
you will see both some_package and some_package.some_module among the
entries. The first is the result of executing some_package/__init__.py.
As usual, that code will *not* be re-exectured on subsequent imports
involving some_package.
> Or can I still do something useful with __init__.py ?
> e
Some packages put something like 'from _default_stuff import *' in
__init__.py with the intention that the package by used as
import package
perhaps [optionally] followed by
import package.specialized_stuff
Terry Jan Reedy
> Yes, you are right. And I can reach everything with
> modules['some_package']
> or variants thereof.
Although note that the usual way to get it would be
to simply do
import some_package
--
Greg