[C++-sig] Re: Converting a C++ object to python

Ron Penton rpenton at adelphia.net
Sun Sep 14 18:29:57 CEST 2003


> Oh, no! HTML....
>> <STYLE></STYLE>
> And a complete lack of style, too :-)

Oh dear, I forgot to reset my mail program after a recent reformat... oopsie
=)


>If you catch a boost::python::error_already_set in C++, I guess you
>can get more information by calling PyErr_Print(), which should dump a
>standard Python traceback on stderr. At a guess, you're getting a
>Python TypeError from the object constructor, because it doesn't have
>a converter for booga *. BTW, why are you passing a pointer to b,
>instead of a reference?

PyErr_Print says "TypeError: No Python class registered for C++ class class
booga",
which confirms what you thought.

The part that confuses me is the converter part; I'm not quite sure how to
go about creating one. All of the examples I can find go about the creation
of the python types manually, rather than using the class_ definition, so
I'm really unsure of where to go from here.


>I don't have any experience embedding Python in C++, because I work
>the other way around (i.e. using C++ extensions from within Python).
>However, the documentation for PyImport_AppendInittab says that you
>should call it *before* Py_Initialize. I would have thought you want a
>normal import of your module anyway, rather than trying to make it act
>like a built-in.

It works either way. For the time being I'm just playing around trying to
see what can be done.






More information about the Cplusplus-sig mailing list