handling modules in packages

Tommy Grav tgrav at mac.com
Wed Sep 5 10:07:01 EDT 2007


>>
> The simplest thing to do would be to have PyAstro.__init__.py  
> import all
> the sub-modules, and define __all__ as the set of names that the  
> package
> should inject into importing modules.
>
> Then you could write (for example)
>
> from PyAstro import numpy, constants, conversion, obsrvations
>
> However if you are simply worried about run-time efficiency then don't
> be: once a module is imported further imports essentially reduce to
> checking that the module is already present in the sys.modules  
> dict, and
> so take almost no time at all.

So am I understanding it right that a second import numpy statement
in a different module (and thus a different namespace) just results in
a binding to the already existing numpy "object"?

Cheers
   Tommy





More information about the Python-list mailing list