On Fri, 2006-08-18 at 16:38 +0000, glenn wrote:
> In controller.py is '@turbogears.expose' - Im very new to python and
> can't find anything substantial on the python site, dive into python or
> the orielly learing python book about what '@' does - wasnt sure if to
> put this in a comp.lang.python or here - so could someone indulge a
> newbie and help me out by explaining what that line does and the role
> of the '@'
> thanks
The @ signifies that a function is decorated. A decorator is a function
that takes a function as an argument, and transforms it, returning
another function.
The following code:
class A:
@turbogears.expose()
def index(self):
pass
is equivalent to the following:
class A:
def index(self):
pass
index = turbogears.expose()(self.index)
The @ syntax was introduced in Python 2.4, You will often see the
alternative syntax used for backwards compatibility.
HTH
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---