decorators tutorials

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Jul 23 15:48:31 CEST 2007


james_027 <cai.haibin at gmail.com> writes:

> Hi all,

(Please don't top-post your reply. Instead, remove from the quoted
material all the parts that are irrelevant to your reply, and post
underneath what you're responding to, in normal chronological order
like any other discussion.)

> 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
> 
> @check_login
> def method2(input):
>     print "I am method TWO. Input %s" % input

That looks okay. What is unclear?

-- 
 \        "I went to court for a parking ticket; I pleaded insanity. I |
  `\   said 'Your Honour, who in their right mind parks in the passing |
_o__)                                        lane?'"  -- Steven Wright |
Ben Finney



More information about the Python-list mailing list