I am trying to do the following:
If i have:
class A():
def a(self):
return 1
class B():
def b(self):
return A()
i can do
new_b = B()
new_b.b().a() # this returns 1
My questions is:
How can i do b().a() where b and a are are given as funct parameters in a method.
I.E: the following:
def f(f1, f2):
return f1().f2()
new_a = A()
f_a = new_a.a
new_b = B()
f_b = new_b.b
f(f_b, f_a) # error
Traceback (most recent call last): File "", line 1, in File "", line 2, in f AttributeError: 'A' object has no attribute 'f2'
Additionally, can i provide f_b as a string "b" and still be able to call it?
Aucun commentaire:
Enregistrer un commentaire