[Tutor] apply() vs. the extended call syntax

Tim Johnson tim at akwebsoft.com
Sat Aug 3 17:26:13 CEST 2013


* Peter Otten <__peter__ at web.de> [130803 07:11]:
> 
> func, args = func_D[k]
> func(*args)
  Of course! Much cleaner and clearer. 
> looks pretty clean. Alternatively, if the arguments are fixed anyway, change 
> the dict to store only no-arg functions. You can make them on the fly with 
> lambda expressions or functools.partial():
> 
> from functools import partial
> 
> func_dict = {
>    "key1": partial(test_apply, "one", "two"),
>    "key2": func_two,
>    "key3": lambda: foo + bar/baz,
> }
> ...
> func_dict[k]()
  ... and it remains quite easy for one to 'rool their own' apply()
  Thanks for the tip, Peter
  regards
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com


More information about the Tutor mailing list