Skip to content

Instantly share code, notes, and snippets.

@ksato9700
Created January 8, 2012 20:38
Show Gist options
  • Save ksato9700/1579602 to your computer and use it in GitHub Desktop.
Save ksato9700/1579602 to your computer and use it in GitHub Desktop.
How to check python class instance
<type 'instance'> __main__.A True True
<class '__main__.B'> <class '__main__.B'> True True
<type 'int'> <type 'int'> False False
<type 'tuple'> <type 'tuple'> False False
<type 'list'> <type 'list'> False False
<type 'dict'> <type 'dict'> False False
<class '__main__.DD'> <class '__main__.DD'> True True
<type 'bool'> <type 'bool'> False False
class A: pass
class B(object): pass
class DD(dict): pass
a = A()
b = B()
i = 0
t = ()
l = []
d = {}
dd = DD()
f = False
for p in (a, b, i, t, l, d, dd, f):
print type(p),
print p.__class__,
print hasattr(p, "__dict__"),
print p.__class__.__module__ != "__builtin__"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment