At 10:36 PM 8/7/04 +1000, Andrew Durdin wrote: >The first assignment to a is binding a reference to a function; the >second is calling the function. This is a very significant difference >in python, and I'm concerned that all the current proposed decorator >syntaxes[*] are liable to cause confusion on this point. For example: > >def foo_decorator(func): > print "no params to this" > return func > >def bar_decorator(func, param): > print param > return func > >@foo_decorator >@bar_decorator("one param here") >def decorated_func(): > pass > >Here the first decorator statement is bare, while the second one >includes parentheses and an argument; the first one looks like a >function reference, while the second looks like a function call. Your example will fail, saying that bar_decorator is being called without enough arguments. Decorator syntax does *not* provide currying. You have to write something like this: def bar_decorator(param): def decorate(func): print param return func return decorate in order for your example to work.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4