embedding python and new-style classes

mike me at no.where
Mon Sep 29 13:28:13 EDT 2003


Hi All,

I have some "new-style" classes written in Python that I would like to embed
inside a C++ application (somewhat grudgingly - if I had my way, the whole
thing would be written in Python).  Anyway, I've done this once before, but
that was with "classic" Python classes.  In that case, I used
PyDict_GetItemString to get a reference to the class I wanted and then used
PyInstance_New() to create the instances.

With the new-style class, the thing I get back from PyDict_GetItemString
appears to be a type reference (rather than a class).  So instead of using
PyInstance_New(), I tried using PyType_GenericNew() (the API seemed
analogous).  However, it doesn't look like the __new__ or __init__ methods
of my underlying Python object are being invoked.  I don't have a lot of
experience with this, so I'm not sure if I've simply made a mistake or
whether I'm going about this all wrong.  If someone could tell me the proper
API calls for  instantiating a new-style class, or point me to an example,
I'd really appreciate it.

Thanks in advance,
mike









More information about the Python-list mailing list