By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,688 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,688 IT Pros & Developers. It's quick & easy.

What is "@" used for ?

P: n/a
Hi.

I am noob in python. while reading some source code I came across ,
this funny thing called @ in some function ,

def administrator(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
user = users.get_current_user()
if not user:
if self.request.method == "GET":

self.redirect(users.create_login_url(self.request. uri))
return
raise web.HTTPError(403)
elif not users.is_current_user_admin():
raise web.HTTPError(403)
else:
return method(self, *args, **kwargs)
return wrapper

now what is that "@" used for ? I tried to google , but it just omits
the "@" and not at all useful for me(funny!! :D)

It will be enough if you can just tell me some link where i can look
for it..

Thank you in advance. :D

Jun 29 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Lie
On Jun 29, 3:39*pm, gops <patelgo...@gmail.comwrote:
Hi.

I am noob in python. while reading some source code I came across ,
this funny thing called @ in some function ,

def administrator(method):
* * @functools.wraps(method)
* * def wrapper(self, *args, **kwargs):
* * * * user = users.get_current_user()
* * * * if not user:
* * * * * * if self.request.method == "GET":

self.redirect(users.create_login_url(self.request. uri))
* * * * * * * * return
* * * * * * raise web.HTTPError(403)
* * * * elif not users.is_current_user_admin():
* * * * * * raise web.HTTPError(403)
* * * * else:
* * * * * * return method(self, *args, **kwargs)
* * return wrapper

now what is that "@" used for ? I tried to google , but it just omits
the "@" and not at all useful for me(funny!! :D)

It will be enough if you can just tell me some link where i can look
for it..

Thank you in advance. :D
@ is decorator. It's a syntax sugar, see this example:
class A(object):
@decorate
def blah(self):
print 'blah'

is the same as:
class A(object):
def blah(self):
print 'blah'
blah = decorate(blah)

Now you know the name, I guess google will help you find the rest of
the explanation.
Jun 29 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.