title: python: What happens when class attribute, instance attribute, and method all have the same name?
body: <p>How does python differentiate a class attribute, instance attribute, and method when the names are the same?</p>
  
  <pre><code>class Exam(object):
  
      test = "class var"
  
      def __init__(self, n):
          self.test = n
  
      def test(self):
          print "method : ",self.test
  
  test_o = Exam("Fine")
  
  print dir(test_o)
  
  print Exam.test
  print test_o.test
  test_o.test()
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__',    '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'test']
  &lt;unbound method load.test&gt;
  Fine
  Traceback (most recent call last):
    File "example.py", line 32, in &lt;module&gt;
      test_o.test()
  TypeError: 'str' object is not callable
  </code></pre>
  
  <p>How to call </p>
  
  <ol>
  <li>class attribute,      <code>Exam.test</code> --> <code>&lt;unbound method load.test&gt;</code> output shows method</li>
  <li>instance attribute    <code>test_o.test</code>  --> <code>"Fine"</code></li>
  <li>method                <code>test_o.test()</code> --> <code>TypeError: 'str' object is not callable</code></li>
  </ol>