How do I create a vanilla object in C?
sturlamolden
sturlamolden at yahoo.no
Sun Nov 22 04:57:49 EST 2009
On 22 Nov, 04:05, Carl Banks <pavlovevide... at gmail.com> wrote:
> name = PyString_FromString("vanilla");
> bases = PyTuple_New(0);
> dict = PyDict_New();
> vanilla_type = PyObject_CallObject(
> &PyType_Type,name,bases,dict,0);
>
> Then call the vanilla type (however you create it) to get a vanilla
> object:
>
> vanilla_object = PyObject_CallObject(vanilla_type,0);
>
> Definitely not the most straightforward thing to do from C.
It is much easier to do this from Cython.
cdef class foo:
# fields stored in C struct
pass
class foo:
# fields stored in Python dict
pass
The let the Cython compiler generate the C code you need.
http://docs.cython.org/src/tutorial/cdef_classes.html
More information about the Python-list
mailing list