I’m pretty new to Python and I have a situation where I have a variable representing a function inside of a module and I’m wondering how to call it dynamically. I have filters.py:
def scale(image, width, height):
pass
And then in another script I have something like:
import filters
def process_images(method='scale', options):
filters[method](**options)
… but that doesn’t work obviously. If someone could fill me in on the proper way to do this, or let me know if there is a better way to pass around functions as parameters that would be awesome.
To avoid the problem, you could pass the function directly, instead of “by name”:
If you have a special reason to use a string instead, you can use
getattras suggested by SilentGhost.