The namedtuple()
constructor returns a class, not an instance itself. You are adding methods to that class. As such, your lambda's must accept a self
argument.
In any case, you should create instances of the named tuple class you created. If you don't want to give your lambdas a self
first argument, adding them to the instance you then created would work fine:
from equations import *
from collections import namedtuple
Struct = namedtuple("struct", "name f1 f2")
class Test:
def __init__(self, nr):
self.obj = self.create(nr)
print self.obj.name
print self.obj.f1(2)
def create(self, nr):
obj = Struct(str(nr), *get_func(nr))
return obj
test = Test(1)