From a series of string, I am trying to call methods inside a class.
Unfortunately, The method is not called properly because it needs the self
to indicate it is internal to the class. How can I fix that logic?
class SomeClass(object):
def apply(self):
rules = [{'action': 'replace'}, {'action': 'split'}, {'action': 'remove'}]
return [eval('_perform_' + r['action'])() for r in rules
if r['action'] in ['replace', 'split', 'remove']]
def _perform_replace(self):
print("performing replace")
def _perform_split(self):
print("performing split")
def _perform_remove(self):
print("performing remove")
SomeClass().apply()
This throws following exception:
NameError: name '_perform_replace' is not defined