[Pyrex] Getting address of ob_type

Nicholas Riley njriley at uiuc.edu
Sat Dec 30 20:34:38 UTC 2006


On Dec 29, 2006, at 1:50 PM, Lenard Lindstrom wrote:

> print (<PyObject *>o).ob_type.tp_name

Thanks, it works.  I didn't realize you could cast a Python object  
like that.  For completeness, this is what I used:

cdef extern from "object.h":
     ctypedef struct PyTypeObject:
         char *tp_name
     ctypedef struct PyObject:
         PyTypeObject *ob_type

cdef unsigned long type_addr(object object_):
     return <unsigned long>&(<PyObject *>object_).ob_type

--Nicholas



More information about the Pyrex mailing list