Instantiating classes which are derived from built-in types.

Achim Dahlhoff Achim.Dahlhoff at t-online.de
Tue Nov 29 09:01:52 CET 2005


Hi.

I'm trying to find out the diffrence between normal classes and classes 
derived from built-in types.
(Which is causing me trouble trying to instantiate a class using C API 
calls)

>>> class A:
...  pass
...
>>> class B(dict):
...  pass
...
>>> type(A)
<type 'classobj'>
>>> type(B)
<type 'type'>
>>>


When I have a handle to A as a PyObject, I can create an instance using 
PyInstance_New(). When I have a handle to B, this does not work as the 
function wants a class PyObject.
I found that the API function PyType_GenericNew() can create something from 
the B type, but it does not call any constructors.

(using the 'dict' here is an example. In my case, I'm using a self-defined 
type I'm using as an API into the C++ part of the software.)

Anyone know how an object could be instantiated using a handle to B?


thanks,


Achim Dahlhoff.





More information about the Python-list mailing list