C API Q I : calling Python methods from C

Johan Hahn johahn at delta.telenordia.se
Sun Apr 14 05:09:00 EDT 2002


Hi

I can't figure out how to call methods written in python from C using the
low level API.

I can call functions though. So for now I create the instance in python when
importing the module and provide a helper function to call the methods. It
looks like this:

/* b4 module */
import code
iii = code.InteractiveInterpreter()
def runsource(code):
    iii.runsource(code)


I manage to import a module, read the modules dictionary, get a class from
the dictionary and create an instance of that class, but I can't find the
right way to get a callable object out of that.
You are supposed to read the class' dictionary for methods, convert a method
to a function and call the function with the instance as the first
parameter, right?
So if anyone can post an example on how to do that it would be of enormous
help!


thanks beforehand,
Johan







More information about the Python-list mailing list