creating an object in embedded python
Brian Quinlan
brian at sweetapp.com
Tue May 13 19:00:12 EDT 2003
> How do I create an instance of an class and then call
> methods within that instance in embedded python?
Just break down the steps that would happen in Python code:
import foo
f = foo.Bar()
=>
import foo
f = getattr(foo, "Bar")()
=>
class = PyObject_GetAttr(module, "Bar")
inst = PyObject_CallFunctionObjArgs(class, ..., NULL)
/* Or use PyObject_CallFunction */
retval = PyObject_CallMethod( inst, "mymeth", "i", myint );
/* Make sure that you get rid of the references that you don't need */
Cheers,
Brian
More information about the Python-list
mailing list