Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Warrick Newsgroups: comp.lang.python Subject: Re: Where is decorator in this example code? Date: Sat, 14 Nov 2015 13:37:44 +0100 Lines: 43 Message-ID: References: <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de tcNB2F6Bw/H9pcyBwavK1wvF52oU6OdkwNbWiSn/ARWA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.045 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'subject:code': 0.07; 'definition,': 0.09; 'effect.': 0.09; 'output': 0.13; 'question.': 0.13; 'code?': 0.16; 'enough.': 0.16; 'example?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tags.': 0.16; 'them.)': 0.16; 'wrote:': 0.16; '2015': 0.20; 'class,': 0.22; 'decorator': 0.22; 'thanks,': 0.24; 'tried': 0.24; 'examples': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message- id:@mail.gmail.com': 0.27; '14,': 0.27; 'executing': 0.27; 'function': 0.28; 'wraps': 0.29; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'role': 0.32; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'clear': 0.35; 'comment': 0.35; 'there': 0.36; 'url:org': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'received:209': 0.38; 'hi,': 0.38; 'application': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'john': 0.61; 'skip:n 10': 0.62; 'saturday,': 0.63; 'great': 0.63; 'between': 0.65; 'here': 0.66; 'link:': 0.69; 'obvious': 0.76; 'doe': 0.84; 'subject:Where': 0.84; 'subject:this': 0.85; '(running': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=conAfIx4XxIPi7OunntSBS7+xlPW6I88nA61r1DEuEQ=; b=DfA5cRcnmtCURBE0XsixcN/HCbkJ9ERwCKqgYn5Far8GgLqwdXO16933OCIa5WSlpn Y0g03wPB16F2MBSS1uLpUqFwNb3ni6actJ6U/FdLhJNhipcGd8tuY/vw38ptorf8vkcY DV0SrP9t6EdxAbNMBKoO4USN73imQCkiczX96qBPXlmTAuY6yVJwLo6E5APZZPKCLAMg +nxmtLNHDIdFamcXzb6raTteuHSs8wrcc2I0wTE68h43vvC+800w/omvmtYdMlp8CDGv aH8/BELMooaOTuo2PQksa0Y5lv2xaZTeL80//6iYeFgGJHvGvK33ImIRTZklTmxsePEb GSSQ== X-Received: by 10.31.167.72 with SMTP id q69mr2914728vke.69.1447504664272; Sat, 14 Nov 2015 04:37:44 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98805 On 14 November 2015 at 13:13, fl wrote: > On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: >> Hi, >> >> I am learning decorator following this link: >> >> http://thecodeship.com/patterns/guide-to-python-function-decorators/ >> >> When I read decorator on class, I don't see decorator taking in effect. >> In the following code snippet, there is the same print out if I comment out >> two lines 'def p_decorate(func):' and '@p_decorate'. >> >> Can you tell me what role of decorator in this code? [snip code] > > My OP may not be clear enough. Here is the key question. After the function > definition, there is no obvious decorator application in the function call: > > my_person = Person() > print my_person.get_fullname() > > Where is the difference between the non-decorator and decorator in this > example? > > Thanks, > -- > https://mail.python.org/mailman/listinfo/python-list Have you tried executing the code with and without the decorator? $ python2 without-decorator.py John Doe $ python2 with-decorator.py

John Doe

Basically, the decorator wraps the output of your get_fullname function with HTML

tags. (Running code examples is a great way to understand them.) -- Chris Warrick PGP: 5EAAEA16