Код: Выделить всё
def GetHelp():
return 'Help'
class MyClass:
def __init__(self):
self.child = 5
def GetChild():
return self.child
x = eval('Get{}()'.format('Help'))
print(x)
obj = MyClass()
y = eval('obj.Get{}()'.format('Child'))
print(y)
Код: Выделить всё
Help
Traceback (most recent call last):
File "/Users/kakyo/Desktop/0.Dev/playground/python/hello_eval.py", line 14, in
y = eval('obj.Get{}()'.format('Child'))
File "", line 1, in
TypeError: GetChild() takes 0 positional arguments but 1 was given
Код: Выделить всё
y = eval('obj.Get{}()'.format('Child'), {'obj': obj})
Подробнее здесь: https://stackoverflow.com/questions/539 ... ct-methods