function wrappers

Scott David Daniels Scott.Daniels at Acm.Org
Wed Oct 10 14:43:34 CEST 2007


Ramon Crehuet wrote:
> def require_int(func):
>       def wrapper(arg):
>           assert isinstance(arg, int)
>           return func(arg)
>       return wrapper
> def p1(a):
>   print a
> p2 = require_int(p1)
> 
> My question is: why do p2 arguments become wrapper arguments? What is 
> the flux of the arguments in the program when you pass functions as 
> arguments?
I suspect you don't understand that each time require_int is called
a _new_ function named wrapper is created (and then returned).

-Scott David Daniels
Scott David Daniels at Acm.Org



More information about the Python-list mailing list