What is "@" used for ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gops

    What is "@" used for ?

    Hi.

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

    def administrator(m ethod):
    @functools.wrap s(method)
    def wrapper(self, *args, **kwargs):
    user = users.get_curre nt_user()
    if not user:
    if self.request.me thod == "GET":

    self.redirect(u sers.create_log in_url(self.req uest.uri))
    return
    raise web.HTTPError(4 03)
    elif not users.is_curren t_user_admin():
    raise web.HTTPError(4 03)
    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

  • Lie

    #2
    Re: What is "@&quot ; used for ?

    On Jun 29, 3:39 pm, gops <patelgo...@gma il.comwrote:
    Hi.
    >
    I am noob in python. while reading some source code I came across ,
    this funny thing called @ in some function ,
    >
    def administrator(m ethod):
        @functools.wrap s(method)
        def wrapper(self, *args, **kwargs):
            user = users.get_curre nt_user()
            if not user:
                if self.request.me thod == "GET":
    >
    self.redirect(u sers.create_log in_url(self.req uest.uri))
                    return
                raise web.HTTPError(4 03)
            elif not users.is_curren t_user_admin():
                raise web.HTTPError(4 03)
            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.

    Comment

    Working...