C API: how to tell if x is a new style instance?

Michal Vitecek fuf at mageo.cz
Thu Jan 29 10:50:50 CET 2004


Mike C. Fletcher wrote:
>Well, I don't actually know how to check for the spiritual state of a 
>new-style class, but here's how to tell if an instance is an instance of 
>a new-style class:
>
>   * Note that a new-style class is a sub-class of type, while
>     old-style classes are not
>   * Check if isinstance( instance.__class__, type )
>   * <Insert mystical spiritual damnedness check here>

 ahh - it helped. thank you!
 
 but, so it means that PyType_Check() doesn't work for new style
 classes' instances? it returns 0 but i understood from the
 documentation that it should return 1:

 """
 int PyType_Check(PyObject *o)
     Returns true if the object o is a type object, including instances
     of types derived from the standard type object. Returns false in
     all other cases.
 """

-- 
		fuf		(fuf at mageo.cz)




More information about the Python-list mailing list