Python equivilent to dlopen/dlsym ?

Alex Martelli aleaxit at yahoo.com
Fri Jun 1 15:55:44 EDT 2001


"Nhi Vanye" <offer at sgi.com> wrote in message
news:9f8fos$cuh4d$1 at fido.engr.sgi.com...
>
> What would be the python equivilent of dlopen()/dlsym(). I'm trying to
> prototype some C code that will use dlopen to open a shared library and
> ldsym() to call a particular function in it.
>
> The python file that implements the functions is listed in a runtime
> configuration file. Because the configuration file will list multiple
> python modules that each have the same function defined (I'll will chain
> them when I call them) I don't want to pollute the name spaces.

You may use __import__() to dynamically load a named module,
and getattr() to obtain the named attribute from the module
object (or the functions in standard module imp, if you need finer
control, but __import__/getattr may mimic well the dlopen/dlsym
distinction you need to prototype).


Alex







More information about the Python-list mailing list