Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Python : Call An Unknow Method With Named Params

DZone's Guide to

Python : Call An Unknow Method With Named Params

·
Free Resource
myObject is an instance of a class
myMethod is the name of the method (string)
myArgs is a dict for named arguments


if hasattr(myObject,myMethod):
    try:
        retValue = getattr(myObject,myMethod)(*(),**(myArgs))
    except TypeError:
        # arguments mismatch
else:
    # there is no "myMethod" method in myObject
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}