Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: from import and __init__.py
Steve Holden
3/25/2010 11:42:00 AM
egbert wrote:
> When I do 'from some_package import some_module'
> the __init__.py of some_package will be run.
> However, there will not be anything like a package-module,
> and the effects of __init__.py seem all to be lost. Is that true ?
> Or can I still do something useful with __init__.py ?
> e
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://pyco...
Holden Web LLC
http://www.hold...
UPCOMING EVENTS:
http://holdenweb.event...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: from import and __init__.py
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password