def validate(request, *args, **kwargs):
form_class = kwargs.pop('form_class')
extra_args_func = kwargs.pop('callback', lambda request, *args, **kwargs: {})
thanks
a={'a':'aaa','b':'bbb'}
b=a.pop('a',lambda x,y:x)
print a
i know dict.pop(‘a’),but i don’t know dict.pop(‘a’,func)
what is the use of ‘func‘ in here
The expression:
builds an anonymous function which must be called with at least one argument (which, if named, must be named
request) and can be called with any number of positional and named arguments: when called, it ignores all the arguments and returns a new empty dictionary.The code snippet:
prints
{'b': 'bbb'}(which is also the valueastays bound this after the snippet executes) and bings the string'aaa'to nameb. The second argument to the.popmethod plays no role in this case: it’s only used when the first argument is not found as a key in the dictionary on which the method is called (in which case,.pop‘s second argument would be the “default value” returned by the call to.pop, without any alteration to the dictionary). In this case,'a'is indeed found at that time as a key in dictionarya, and therefore it’s removed from that dictionary, and the corresponding value, string'aaa', is returned by the call to.pop(whence it gets then bound to nameb).