いくつかのメソッドを含むクラス Population があります。
Population
入力によると、クラスのインスタンスでメソッドを特定の順序で実行したいと考えています。
私が達成しようとしていることをもう少し正確にすることは、使用することとまったく同じです:
stuff = input(" enter stuff ")
dico = {'stuff1':functionA, 'stuff2':functionC, 'stuff3':functionB, 'stuff4':functionD}
dico[stuff]()
functionA、functionB などは関数ではなくメソッドであることを除いて:
order_type = 'a'
class Population (object):
def __init__(self,a):
self.a = a
def method1 (self):
self.a = self.a*2
return self
def method2 (self):
self.a += 2
return self
def method3 (self,b):
self.a = self.a + b
return self
if order_type=='a':
order = {1:method1, 2:method2, 3:method3}
elif order_type=='b':
order = {1:method2, 2:method1, 3:method3}
else :
order = {1:method3, 2:method2, 3:method1}
my_pop = Population(3)
while iteration < 100:
iteration +=1
for i in range(len(order)):
method_to_use = order[i]
my_pop.method_to_use() # But obviously it doesn't work!
私の質問が十分に明確になったことを願っています!私のメソッドの1つは2つの引数を必要とすることに注意してください