Basic importing question

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Aug 20 07:54:15 EDT 2008


Hussein B a écrit :
(snip)
> 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[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.


[1] 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.


[2]  'def' and 'class' are executable statements that create resp. a 
function or class object and bind them to the function/class name in the 
containing namespace.



More information about the Python-list mailing list