Re: from import and __init__.py
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 ?
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.
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/
- Re: Relative import from script with same name as package
... notation) as introduced by PEP 328. ... package member module which uses explicit relative imports. ... you are not using the package by importing its members from code outside the package but you are running them directly. ... on the "import thetest" statement when you run the file directly: then thetest.py is a top level module, and when the interpreter encounters the statement "import thetest" *it is already absolute import*. ...
- Re: How to use select (select(2)) in Perl?
... The assignment has to ... >} occur in a different package from that which you are assigning into. ... as long as use vars continues to work. ... especially in such a way that it was doing the importing from the ...
- Re: Module/package hierarchy and its separation from file structure
... importing under different names, I meant exactly that. ... You could confuse Python adding a package root to sys.path and doing ... because in Java Monkey.java is a class. ...
- Re: import statement - package visibility problem
... > Importing from a not package related source code is not a problem, ... My problem is about importing inside a package. ... > Lib/Server/Db using relative paths ...
- Re: noob questions
... I know integrate is a package this is in scipy. ... I don't understand why after importing everything in scipy (which ... If scipy is specifically designed to support such usage then you should be OK, but in general this can "pollute" your namespace by bringing in all the names defined in the imported package or module within your local namespace. ...