title: Should this method be a classmethod and why can't it access vars?
body: <p>I come from java background, so I am slightly confused here.</p>
  <p>Consider the code snippet below:</p>
  <pre><code>class A():
      def __init__(self, **kwargs):
          self.obj_var = &quot;I am obj var&quot;
  
      @classmethod
      def class_method(cls):
          print cls.obj_var   # this line is in question here
          cls.cls_obj = &quot;I m class object&quot;
          return cls.cls_obj
  </code></pre>
  <p>This throws an error :</p>
  <pre><code>In [30]: a = A()
  
  In [31]: a.obj_var
  Out[31]: 'I am obj var'
  
  In [32]: a.class_method()
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-32-3dcd9d512548&gt; in &lt;module&gt;()
  ----&gt; 1 a.class_method()
  
  &lt;ipython-input-29-9c0d341ad75f&gt; in class_method(cls)
        8     @classmethod
        9     def class_method(cls):
  ---&gt; 10         print cls.obj_var
       11         cls.cls_obj = &quot;I m class object&quot;
       12         return cls.cls_obj
  
  AttributeError: class A has no attribute 'obj_var'
  </code></pre>
  <p>iIf I comment out <code>@classmethod</code>, this will work fine.</p>
  <p><strong>My understanding</strong> (<em>which is incorrect m sure</em>) :</p>
  <p>When I do <code>a = A()</code>, then all the variables(<code>obj_var</code>) created in <code>__init__</code> can be accessed via this <code>a</code> when passed to any other <code>classmethod</code> of same class.Apparently this is not the case.</p>
  <p><strong>Question(s)</strong></p>
  <ul>
  <li><p>why am i not able to access <code>__init__</code> <code>var</code>s  in <code>class_method</code> when decorater <code>@classmethod</code> is mentioned in the method but on removing the decorater, it works fine?</p>
  </li>
  <li><p>how python internally process this particular class upon compilation?</p>
  </li>
  <li><p>is there any way i can use <code>@classmethod</code> and the <code>__init__</code> vars in same method?</p>
  </li>
  </ul>