title: updating instance attributes from global function with many arguments
body: <p>I have a global function meant to map a class attribute to a class property</p>
  
  <pre><code>def f(x):
      return x**2
  </code></pre>
  
  <p>The class is </p>
  
  <pre><code>class toy:
      def __init__(self,x):
          self.x=x
  
      @property
      def y(self):
          return f(self.x)
  </code></pre>
  
  <p>so </p>
  
  <pre><code>t = toy(2)
  </code></pre>
  
  <p>gives 
  t.x = 2 and t.y = 4. </p>
  
  <p>If I set t.x=3, I get t.y = 9. This is the desired behavior. My question is this: </p>
  
  <p>What is the proper way to do this with a function of multiple arguments? </p>
  
  <p>For example, if </p>
  
  <pre><code>def g(x,a,b):
      return a*x**2+b 
  </code></pre>
  
  <p>controlled the property y, and a,b were fixed outside of the class definition, is it okay to write</p>
  
  <pre><code>class toy:
      def __init__(self,x):
          self.x=x
  
      @property
      def y(self):
          return g(self.x,a,b) 
  </code></pre>
  
  <p>Or is there a better way to do this? How can I pass global variables into the local scope of a class instance, in order to determine a property of the instance? </p>