title: How to determine the type of class instance
body: <p>To determine the class, I can do so:</p>
  
  <pre><code>class A: pass    
  a = A
  
  type(A) is type #True
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>import inspect
  inspect.isclass(A) 
  </code></pre>
  
  <p>But how to determine the type of class instance, not knowing the class name?</p>
  
  <p>Something like this:</p>
  
  <pre><code>isinstance(a, a.__class__.__name__)
  #TypeError: isinstance() arg 2 must be a type or tuple of types
  </code></pre>
  
  <p>I found one solution, but it does not work with Python 3x</p>
  
  <pre><code>import types
  
  class A: pass
  a = A()
  
  print(type(a) == types.InstanceType)
  #AttributeError: 'module' object has no attribute 'InstanceType'
  </code></pre>
  
  <p><strong>Solution:</strong></p>
  
  <pre><code>if '__dict__' in dir(a) and type(a) is not type:
  </code></pre>