title: Using an attribute as argument of a method of the same class
body: <p>I want to define an attribute of a class and then use it as argument of a method in the same class in the following way</p>
  
  <pre><code>class Class1:
      def __init__(self,attr):
          self.attr=attr
      def method1(self,x=self.attr):
          return 2*x
  
  
  </code></pre>
  
  <p>It returns an error: <code>NameError: name 'self' is not defined</code></p>
  
  <p>How can I define the method in such a way that whenever I don't write <code>x</code> explicitly it just uses the attribute <code>attr</code> ?</p>
  
  <p>In the example, what I mean is that I would like to have</p>
  
  <pre><code>cl=Class1()
  print cl.method1(12) # returns '24'
  cl.attr= -2
  print cl.method1() # returns '-4'
  </code></pre>