confused in decorate and closure
月忧茗
yueyoum at gmail.com
Wed Sep 12 22:55:03 EDT 2012
HI, I have some test code:
def num(num):
def deco(func):
def wrap(*args, **kwargs):
inputed_num = num
return func(*args, **kwargs)
return wrap
return deco
@num(5)
def test(a):
return a + inputed_num
print test(1)
when run this code, I got an error shows that 'inputed_num' is not defined
My question is:
In wrap function, is there not a closure that func can got 'inputed_num' ?
Anyway, If not, how should I do to got my aim: Initialize some value, and
use this value directly in the main function.
Thinks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120913/0189da25/attachment.html>
More information about the Python-list
mailing list