Extending Python dynamically

ScherBi at BAM.com ScherBi at BAM.com
Thu Nov 4 13:27:29 EST 1999

> Thank you for your help. The method you suggested works perfectly!

You're quite welcome.

> However, I do not understand completely how the Python 
> interpreter finds out that it has to load an so file. Normally -- I
believed -- 
> when Python sees an "import xxx" statement it looks for a xxx.py, xxx.pyc
> xxx.pyo file in the $PYTHONPATH directories or an xxx subdirectory having
> __init__.py file, but not an xxx.so file. This means that if I add the
> directory to the $PYTHONPATH (such as export PYTHONPATH='.' Python will
> any arbitrary so file in the $PWD?

The true answers to these questions are at level lower than I am able to go
into in Python, primarily because I think the answers are in Python's c
Anyway, I believe that Python, on execution of imort xxx, will load xxx.so
if, and only if, it has the proper interface, that is, if it has been built
as a Python extension.
Try it with any other .so file and see what happens.

> Anyway, I am very happy that I do not have to recompile 
> Python every time I add a new extension library (ie. an so file) :-).

Yes, while others may deride possible performance degradation of the shared
object interface, I have been known to ignore an extension or two because it
required me to rebuild Python, but I'm really out of my league here.


More information about the Python-list mailing list