tags:

views:

588

answers:

6

like @login_required?

+27  A: 

It is decorator syntax.

A function definition may be wrapped by one or more decorator expressions. Decorator expressions are evaluated when the function is defined, in the scope that contains the function definition. The result must be a callable, which is invoked with the function object as the only argument. The returned value is bound to the function name instead of the function object. Multiple decorators are applied in nested fashion.

So doing something like this:

@login_required
def my_function():
    pass

Is just a fancy way of doing this:

def my_function():
    pass
my_function = login_required(my_function)

For more, check out the documentation.

Paolo Bergantino
:) Nice edit ... *deletes own answer* :P
Aiden Bell
Also +1 ... FTW
Aiden Bell
+1  A: 

It's a decorator. More here: http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

f0b0s
that is not an answer to the question.
NicDumZ
+1  A: 

A decorator, also called pie syntax. it allows you to "decorate" a function with another function. You already had decoration with staticmethod() and classmethod(). The pie syntax makes it more easy to access and extend.

Stefano Borini
"pie syntax"? Never heard of that before. Can you cite its origin or explain more?
duffymo
from the wiki, during the discussion about the choice. I think it comes from java traditional naminghttp://wiki.python.org/moin/PythonDecorators#A1.piedecoratorsyntax
Stefano Borini
+2  A: 

If you ask this type of question you will probably be interested in the other hidden features of Python.

wr
+1  A: 

That specific decorator looks like it comes from Django.

It might help you get a better understanding by reading the Django documentation about that decorator.

Mattias Nilsson