def cclass(arg1):
... if True:
... class klass (object):
... print arg1
... def __init__(self,arg1):
... self.arg1=arg1
... def klassfunc(self):
... arg2=self.arg1
... print arg2
... return klass()
This code naturally produces an error message:
>>> test=cclass('astring')
astring
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "<interactive input>", line 10, in cclass
TypeError: __init__() takes exactly 2 arguments (1 given)
My question is: how should I pass the functions arg1 on to the class?
Just pass it into the constructor, like you would do for any other python class. 🙂