[C++-sig] Re: Creating an instance of a python class derived from a C++ object from C++
Brian Hall
bhall at gamers-fix.com
Sat Jul 10 22:03:03 CEST 2004
>
> Now say I want to dynamically create an instance of a python class derived
> from MyCppClass like so:
>
> class MyPythonClass(MyCppClass):
> def SomeFunction(self):
> return 42
>
> But I want to do this from C++, not Python... how would I do this?
Use the metaclass interface:
// returns a new class
object make_bar
{
object bases = make_tuple(py_cState);
dict attributes;
attributes['x'] = 1;
attributes['quack'] = quack;
return py_cState.attr("__class__")("bar", bases, attributes);
};
----------------
While this is very very cool, I think you misunderstand me... I have the
python script, and I want to instantiate a python object of type
MyPythonClass from C++ not define it from C++.
Thanks again!
Brian
More information about the Cplusplus-sig
mailing list