@func call syntax

T

teekaysoh

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.
 
C

casevh

?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

this is decorator, this is how it's may be implented
.... def dec(f):
.... def wrapped(*args, **kwargs):
.... ret = f(*args, **kwargs)
.... assert type(ret) is t
.... return ret
.... return wrapped
.... return dec
........ def f1():
.... return 1
........ def f2():
.... return 2.0
........ def f3():
.... return 1
....Traceback (most recent call last):
File "<stdin>", line 1, in ?


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top