7 examples of 'python call method by name' in Python

Every line of 'python call method by name' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
434def call_object_method(obj, method_name, method_args):
435 """
436 Dynamically call a method from a given object
438 @param obj: target object
439 @param method_name: name of a method to be called
440 @param method_args: dictionary of arguments to be passed to the target method
442 @return: returned value from calling the target method
443 """
445 return getattr(obj, method_name)(**method_args)
23def replace_method(klass, method_name, func):
24 m = new.instancemethod(func, None, klass)
25 setattr(klass, method_name, m)
22def __getattr__(self, name):
23 f = getattr(vm, name)
24 return f
26def _call_method_with(lib, name, *args):
27 if hasattr(lib, name):
28 getattr(lib, name)(*args)
29 else:
30 raise RuntimeError('failed to call %s' % name)
402def method(self, name_c: Optional[str] = None, **kwargs):
403 """Decorator. The same as ``.function()`` with ``wrap=True``."""
404 return self.function(name_c=name_c, wrap=True, **kwargs)
132def get_method(self, method_name):
133 method = getattr(self, method_name, None)
134 if not is_gilbert_method(method):
135 return None
136 return method
522def get_method(node, name):
523 """look for a method astng in the given class node or its ancestors
524 """
525 try:
526 return node.resolve_method(name)
527 except NotFoundError:
528 class_node = node.get_ancestor_for_method(name)
529 if class_node is not None:
530 # get astng for the searched method
531 return class_node.resolve_method(name)
532 raise NotFoundError(name)

Related snippets