I want to create a bunch of methods in class __init__ method dynamically. Havent had luck so far.
CODE:
class Clas(object):
def __init__(self):
for i in ['hello', 'world', 'app']:
def method():
print i
setattr(self, i, method)
Than I crate method and call method that is fitst in list.
>> instance = Clas()
>> instance.hello()
'app'
I expect it to print hello not app. WHat is the problem?
In addition, each of these dynamically assigned methods referred to the same function in memory, even if I do copy.copy(method)