I need to call a function that handles a list of arguments that can have default values:
example code:
web.input(name=None, age=None, desc=None, alert=None, country=None, lang=None)
How can I call web.input like this using a list or dictionary? I'm stuck at:
getattr(web, 'input').__call__()
my_args = {'name': 'Jim', 'age': 30, 'country': 'France'}
getattr(web, 'input')(**my_args) # the __call__ is unnecessary
You don't need to use getattr either, you can of course just call the method directly (if you don't want to look up the attribute from a string):
web.input(**my_args)
You can do the same thing with lists:
my_args_list = ['Jim', 30, 'A cool person']
getattr(web, 'input')(*my_args_list)
is equivalent to
getattr(web, 'input')('Jim', 30, 'A cool person')
find here the relevant documentation
web.input(*list)
web.input(**kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With