Basic importing question
bruno.42.desthuilliers at websiteburo.invalid
Wed Aug 20 13:54:15 CEST 2008
Hussein B a écrit :
> Thank you both for your kind help and patience :)
> Built-in modules are compiled
For which definition of "compiled" ?
> but even if they are so, when importing
> them (sys for example), Python will run their code in order to create
> bindings and objects, right?
As the name imply, built-in modules are built in the interpreter - IOW,
they are part of the interpreter *exposed* as modules. 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 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.
 There's an ambiguity with the term "module", which is used for both
the module object (instance of class 'module') that exists at runtime
and the .py source file a module object is usually - but not necessarily
- built from.
 'def' and 'class' are executable statements that create resp. a
function or class object and bind them to the function/class name in the
More information about the Python-list