Type of an object:

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Dec 17 11:35:10 CET 2013

Steven D'Aprano wrote:
> I think I need to see an actual working demonstration, because as far as 
> I can see, type(obj) returns obj.__class__.


 >>> class C(object):
...  def f(self):
...   return "Surprise!"
...  __class__ = property(f)
 >>> c = C()
 >>> type(c)
<class '__main__.C'>
 >>> c.__class__

It appears that type() bypasses the attribute access
mechanism and goes straight for the actual type.


More information about the Python-list mailing list