Dpulicating "class Foo:" in C
Walter Dörwald
walter at livinglogic.de
Fri Jul 19 13:09:17 EDT 2002
Mark Charsley wrote:
> In article <memo.20020719121547.1864A at a.a>,
> mark.charsley at REMOVE_THIS.radioscape.com (Mark Charsley) wrote:
>
> OK got a little further. The following seems to work fine
>
> PyObject* newModule = PyImport_ImportModule("new");
>
> PyObject* new_classobj = PyObject_GetAttrString(newModule,"classobj");
> PyObject* args = Py_BuildValue("s(){}","Configure");
>
> PyObject* ConfigClass = PyEval_CallObject(new_classobj,args);
>
> However the following crashes nastily whenever I try to do anything with
> ConfigClass...
>
> PyObject* types = PyImport_ImportModule("types");
>
> PyObject* classType = PyObject_GetAttrString(types,"ClassType");
>
> PyObject* ConfigClass = _PyObject_New((PyTypeObject*)classType);
>
> Is there any way to create a new Class Object from C without having to
> call into new.classobj?
In Include/classobject.h there's a
PyObject *PyClass_New(PyObject *, PyObject *, PyObject *);
Arguments seem to be:
* tuple of base classes
* class attribute dictionary
* class name
But PyClass_New isn't documented, so I wonder, if it's
part of the official API. At least, the function name does
indicate that it is.
Bye,
Walter Dörwald
More information about the Python-list
mailing list