Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:209.85.223': 0.03; 'called.': 0.09; 'def': 0.10; 'to:name:python-list': 0.15; 'output?': 0.16; '>>>': 0.18; '>>>': 0.22; 'message- id:@mail.gmail.com': 0.27; 'lines': 0.28; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'to:addr:python.org': 0.39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=er2COUgaGGIF+13F+dYTohBoUgRj2naO9IrE44Igu7k=; b=CUkk1EEMCR1nJ0BDmSplwmFBcOGdoSzv2bfbp1nX7jtrsmS9Tj3PpgmiEu1+zJUK+o UYkU2H9pD9CatCtRTT143gZB9HromgMcw7jdeGlcBsWBenTxxh7T9K03VlPV8xV/HmZx SHDSfR6AfQpXQK70EQEoZym62GLOW8Q3ZQ3sALaTN86+HtiRXW/+F9MQnxa/vFUffIVL ycA0g9jWCQgvl13NktPm+9atVZvSp1f931blDLlkYFiXNMfE30Bd2CTZrB5t1290PoO6 bD3AReqlz6Qzr076IswOncvGOsJxY3dVKQDBnFLfKJOZAzcIRmKYYVF4NW4u2/lWxrCQ RnIA== MIME-Version: 1.0 X-Received: by 10.50.158.165 with SMTP id wv5mr1810721igb.3.1358259604515; Tue, 15 Jan 2013 06:20:04 -0800 (PST) Date: Tue, 15 Jan 2013 22:20:04 +0800 Subject: i can't understand decorator From: contro opinion To: python-list Content-Type: multipart/alternative; boundary=14dae934062f3d6a2304d3547532 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358259607 news.xs4all.nl 6848 [2001:888:2000:d::a6]:52648 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36853 --14dae934062f3d6a2304d3547532 Content-Type: text/plain; charset=ISO-8859-1 >>> def deco(func): ... def kdeco(): ... print("before myfunc() called.") ... func() ... print(" after myfunc() called.") ... return kdeco ... >>> @deco ... def myfunc(): ... print(" myfunc() called.") ... >>> myfunc() before myfunc() called. myfunc() called. after myfunc() called. >>> deco(myfunc)() before myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. after myfunc() called. 1. why there are two lines :before myfunc() called.and tow lines :after myfunc() called. in the output? 2.why the result is not before myfunc() called. myfunc() called. after myfunc() called. before myfunc() called. myfunc() called. after myfunc() called. --14dae934062f3d6a2304d3547532 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
>>> def deco(func):
...=A0=A0=A0=A0=A0 def kde= co():
...=A0=A0=A0=A0=A0=A0=A0=A0=A0 print("before myfunc() called.= ")
...=A0=A0=A0=A0=A0=A0=A0=A0=A0 func()
...=A0=A0=A0=A0=A0=A0= =A0=A0=A0 print("=A0 after myfunc() called.")
...=A0=A0=A0=A0= =A0 return kdeco
...
>>> @deco
... def myfunc():
...=A0=A0=A0=A0=A0 print= (" myfunc() called.")
...
>>> myfunc()
before = myfunc() called.
=A0myfunc() called.
=A0 after myfunc() called.
&g= t;>> deco(myfunc)()
before myfunc() called.
before myfunc() called.
=A0myfunc() called.=A0 after myfunc() called.
=A0 after myfunc() called.
1.
why the= re are two lines :before myfunc() called.and tow lines :after myfunc() call= ed. in the output?
2.why the result is not
before myfunc() called.
=A0myfunc() called.<= br>=A0 after myfunc() called.
before myfunc() called.
=A0myfunc() cal= led.
=A0 after myfunc() called.
--14dae934062f3d6a2304d3547532--