mean of arobase in python

Fredrik Lundh fredrik at
Wed Jul 23 09:47:10 CEST 2008

Guilhem Faure wrote:

> What means @ in python ?

usually called "at sign" in english.

> In this script for exemple (this script return an error in my konsole...)
> @f1(arg)
> @f2
> def func(): pass
> I see several script where used this symbol but I can't understand.

in your example, "f1(arg)" and "f2" are decorators.  the above is 
equivalent to writing

     def func():
     func = f1(arg)(f2(func))

that is, define a function, and then pass it to the function "f2", and 
then to the function that's returned by calling "f1(arg)".  the final 
value of the "func" variable is whatever the decorators returned.

the decorator functions (f2 and whatever f1(arg) returns) can manipulate
the function being defined, or even replace it with something else.


some (semi-advanced) articles:


More information about the Python-list mailing list