2006年07月20日 星期四 11:34
def require_int (func): def wrapper (arg): assert isinstance(arg, int) return func(arg) return wrapper @require_int def p1 (arg): print arg @require_int def p2(arg): print arg*2 在python文档上讲python2.4上讲decorators有这么一段代码 我运行p1(1)为什么会报错 >>> p1(1) Traceback (most recent call last): File "", line 1, in ? TypeError: 'NoneType' object is not callable
2006年07月20日 星期四 13:42
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def require_int(func): ... def wrapper(arg): ... assert isinstance(arg,int) ... return func(arg) ... return wrapper ... >>> @require_int ... def p1(arg): ... print arg ... >>> p1(1) 1 >>> -- http://codeplayer.blogbus.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060720/261df7be/attachment.htm
2006年07月20日 星期四 13:43
On 7/20/06, crocodile.liu <crocodile.liu at 163.com> wrote: > > def require_int (func): > def wrapper (arg): > assert isinstance(arg, int) > return func(arg) > > return wrapper > > @require_int > def p1 (arg): > print arg > > @require_int > def p2(arg): > print arg*2 > > > 在python文档上讲python2.4上讲decorators有这么一段代码 > 我运行p1(1)为什么会报错 > >>> p1(1) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'NoneType' object is not callable > 没有缩近啊。 -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit
2006年07月20日 星期四 13:59
原来是直接粘上去的代码就不行了,手动在命令行中敲代码就好了 limodou 写道: > On 7/20/06, crocodile.liu <crocodile.liu at 163.com> wrote: >> >> def require_int (func): >> def wrapper (arg): >> assert isinstance(arg, int) >> return func(arg) >> >> return wrapper >> >> @require_int >> def p1 (arg): >> print arg >> >> @require_int >> def p2(arg): >> print arg*2 >> >> >> 在python文档上讲python2.4上讲decorators有这么一段代码 >> 我运行p1(1)为什么会报错 >> >>> p1(1) >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: 'NoneType' object is not callable >> > > 没有缩近啊。 > > ------------------------------------------------------------------------ > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号