Basic importing question
Christian Heimes
lists at cheimes.de
Wed Aug 20 08:51:36 EDT 2008
Bruno Desthuilliers wrote:
> As the name imply, built-in modules are built in the interpreter - IOW,
> they are part of the interpreter *exposed* as modules[1]. Unless you
> have a taste for gory implementation details, just don't worry about this.
>
> Other "ordinary" modules need of course to be executed once when first
> loaded - IOW, the first time they are imported. All statements[2] at the
> top-level of the module are then sequentially executed, so that any
> relevant object (functions, classes, whatever) are created and bound in
> the module's namespace.
Builtin modules like thread, signal etc. as well as C extensions like
socket have an initialization function. The initialization function is
called during the first import of a module. It creates the module object
and assigns objects to its __dict__ attribute.
Builtin modules are statically linked into the Python executable /
library while normal C extensions are shared libraries. Some modules are
builtins because they are required during boot strapping. It's possible
to embed most C modules into the core.
Christian
More information about the Python-list
mailing list