Classes

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 23/02/2011 at 07:38, xxxxxxxx wrote:

Hi there,

i created a class for several calculation. But there is a problem and I can't fiure it out. 😞

import c4d  
import math  
  
class distr_functions() :  
  def __init__(self) :  
      pass  
  def CalcLin(x,xmax) :  
      return x/xmax  
  def CalcPot(x,xmax) :  
      return math.pow(x/xmax,2)  
  def CalcExp(x,xmax,strength = 200) :  
      return math.pow(strength,x/xmax)/strength  
  def CalcCos(x,xmax,puls = 1) :  
      return (-0.5)*math.cos(x/xmax*pi*puls)+0.5  
  def CalcSwitch(x,xmax,switch,third = 1) :  
      if switch == 0:  
          return self.CalcLin(x,xmax)  
      elif switch == 1:  
          return self.CalcPot(x,xmax)  
      elif switch == 2:  
          return self.CalcExp(x,xmax,third)  
      elif switch == 3:  
          return self.CalcCos(x,xmax,third)  
      else: return  
  
  
def main() :  
  df = distr_functions()  
  print df.CalcLin(4,4)  
  
if __name__ == "__main__":  
  main()  

The console tells me:

CalcLin() takes exactly 2 arguments, 3 given

But it works perfectly if i don't put these functions into a class.
What did i wrong in defining the class ?

And can i import a module for a class , like for eg the math module ?

Thanks, nux

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 23/02/2011 at 14:06, xxxxxxxx wrote:

Hi, you forgot the 'self' reference:

def CalcLin(self,x,xmax) :

Cheers, Sebastian