Python
25
Вклад в тег
def cool_staff(form_class, inits, defaults, user, other_param):
# много строчек кода
...
res = cool_staff(form_class=MainForm, inits={a:1, b:3}, defaults=[1,2,3], ...)
...
res = cool_staff(form_class=MainForm, inits={a:100500, b:42}, defaults=[3,2,1], ...)
...
main_cool_staff = lambda **kwargs: cool_staff(form_class=MainForm, **kwargs)
...
res = main_cool_staff(inits={a:1, b:3}, defaults=[1,2,3], ...)
...
res = main_cool_staff(inits={a:100500, b:42}, defaults=[3,2,1], ...)
...
main_cool_staff = lambda *args, **kwargs: cool_staff(form_class=MainForm, *args, **kwargs)
import functools
main_cool_staff = functools.partial(cool_staff, MainForm)
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
>>> for name, phone in table.items():
... print '{0:10} ==> {1:10d}'.format(name, phone)
...
Jack ==> 4098
Dcab ==> 7678
Sjoerd ==> 4127