Answers for "python dynamically call function from string"

1

python calling dynamic function on object

obj = MyClass()
try:
    func = getattr(obj, "dostuff")
    func()
except AttributeError:
    print "dostuff not found"
Posted by: Guest on October-31-2020
1

python execute function from string

import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
Posted by: Guest on April-07-2020
-1

python get function from string name

module = __import__('foo')
func = getattr(module, 'bar')
func()
Posted by: Guest on June-25-2020

Code answers related to "python dynamically call function from string"

Python Answers by Framework

Browse Popular Code Answers by Language