@func call syntax
Hi, I am new to Python, here I'd like to have a question: I noticed a special way to call a function in a program: @function_name No argv is passed, even though the function_name asks for one. Any idea what this @something syntax is trying to achieve. I haven't been able to find any answer of on the google web and groups. TIA. -- http://mail.python.org/mailman/listinfo/python-list
Re: @func call syntax
[EMAIL PROTECTED] wrote: Hi, I am new to Python, here I'd like to have a question: I noticed a special way to call a function in a program: @function_name No argv is passed, even though the function_name asks for one. Any idea what this @something syntax is trying to achieve. I haven't been able to find any answer of on the google web and groups. TIA. @function_name is called a decorator. http://www.python.org/dev/peps/pep-0318/ http://docs.python.org/whatsnew/node6.html casevh -- http://mail.python.org/mailman/listinfo/python-list
Re: @func call syntax
this is decorator, this is how it's may be implented def returns(t): ... def dec(f): ... def wrapped(*args, **kwargs): ... ret = f(*args, **kwargs) ... assert type(ret) is t ... return ret ... return wrapped ... return dec ... @returns(int) ... def f1(): ... return 1 ... @returns(float) ... def f2(): ... return 2.0 ... @returns(str) ... def f3(): ... return 1 ... f1() 1 f2() 2.0 f3() Traceback (most recent call last): File stdin, line 1, in ? File stdin, line 5, in wrapped AssertionError I can imagine that stuff like this may be extremely usefull when testing you program later one could parse and remove all such assertations easy and cut them all at once Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list