where's "import" in the C sources?

Torsten Mohr tmohr at s.netic.de
Thu Dec 30 08:57:12 CET 2004

Hi David,

thanks for the explanation.  That is very helpful to me.

Best regards,

David Bolen wrote:

> Torsten Mohr <tmohr at s.netic.de> writes:
>> i tried to find the file and line in the C sources of python
>> where the command "import" is implemented.  Can anybody give
>> me some hint on this?
> Well, there are several levels, depending on what you are looking for.
> The literal "import" syntax in a source module is translated by the
> Python compiler to various IMPORT_* bytecodes, which are processed in
> the main interpreter loop (see ceval.c).
> They all basically bubble down to making use of the builtin __import__
> method, which is obtained from the builtin module defined in
> bltinmodule.c.
> That in turn makes use of the import processing module whose code can
> be found in import.c - which is the same source that also implements
> the "imp" module to provide lower layer access to to the import
> internals.
> Now, when it comes to physically loading in a module, Python source
> and compiled modules are handled by import (well, not the compiling
> part), but dynamically loaded extension modules are OS specific.  You
> can find the handling of such extension modules in OS-specific source
> files dynload_*.c (e.g., dynload_win.c for Windows).
> All of these files can be found in the dist/src/Python directory in
> the Python source tree.
> -- David

More information about the Python-list mailing list