mean of arobase in python

Fredrik Lundh fredrik at pythonware.com
Wed Jul 23 03:47:10 EDT 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():
         pass
     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.

specification:

     http://www.python.org/dev/peps/pep-0318/

some (semi-advanced) articles:

     http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
     http://www.phyast.pitt.edu/~micheles/python/documentation.html

</F>




More information about the Python-list mailing list