get class instance from C++ extension?

Toshiya Kawakami kawakami at
Tue Jun 19 01:47:46 EDT 2001

Martin von Loewis wrote:
> > Is there any simple example for PyObject_CallFunction()?
> Please have a look at Objects/readline.c. There, you have

I found Modules/readline.c instead.
The PyObject_CallFunction() seems NOT to be a solution for
what I want to do. (wrong?)

Returning to my first question, 
> > How can I return a same information with a python class from C++?
> > ### I want to call C++ extension and get calss c1 instance to y
> > y = myext.meth1( 5, 6, 7.2 )
> > ### and want to print attributes of the got y.
> > print y.a1, y.a2, y.m1()
---static PyObject *method()
> > //  I want to return not an integer but the same structure with
> > // the class c1 defined in test.pi file. How can I do that?

I want to know how should I write codes of the callee C++ method
to return a class instance to the caller python codes, and want
to see examples like following process.
Are there any examples for this?

(1) A python code calls a method extended by C++.
(2) The python code gets a class instance from the C++ method.
   The class instance must be defined in the caller python code,
   or the caller python code must be able to get class format
   (what attribute and methods are included in it) from the
   callee C++ method.
(3) The Returned class instance ("y" above) has attribute and
   methods, and the caller python code can print them as
   "print y.a1, y.a2, y.m1()".

For details about what I want to do, please read my sample
codes in the original message.


More information about the Python-list mailing list