decorators tutorials

james_027 cai.haibin at
Mon Jul 23 11:34:17 CEST 2007

Hi all,

I am having difficulty understanding decorator. The definition was
clear for me, but the syntax is not so clear to me.

will decorators will always have to be in this way

def check_login(func):
    def _check_login(*args):
        print "I am decorator"
        return func(*args)
    return _check_login

def method2(input):
    print "I am method TWO. Input %s" % input


On Jul 23, 4:41 pm, "sjdevn... at" <sjdevn... at> wrote:
> james_027 wrote:
> > Hi,
> > I am learning python by learning django, and I stumble upon decorator
> > which is very cool, any beginners resources for python decorators,
> > although I can google it, I just want to get a good tutorial for this
> > topic.
> Decorators are just a more concise but less obvious way of calling a
> defined function on another function.
> e.g.
> @my_decorator
> def foo():
>    ...
> is the essentially the same as:
> def foo():
>    ...
> foo=my_decorator(foo)

More information about the Python-list mailing list