Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98805

Re: Where is decorator in this example code?

From Chris Warrick <kwpolska@gmail.com>
Newsgroups comp.lang.python
Subject Re: Where is decorator in this example code?
Date 2015-11-14 13:37 +0100
Message-ID <mailman.324.1447504672.16136.python-list@python.org> (permalink)
References <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> <bf73e0ab-2394-42a6-bb53-dd73be3897e3@googlegroups.com>

Show all headers | View raw


On 14 November 2015 at 13:13, fl <rxjwg98@gmail.com> 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
<p>John Doe</p>

Basically, the decorator wraps the output of your get_fullname
function with HTML <p> tags.

(Running code examples is a great way to understand them.)

-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Where is decorator in this example code? fl <rxjwg98@gmail.com> - 2015-11-14 04:10 -0800
  Re: Where is decorator in this example code? fl <rxjwg98@gmail.com> - 2015-11-14 04:13 -0800
    Re: Where is decorator in this example code? Chris Warrick <kwpolska@gmail.com> - 2015-11-14 13:37 +0100
      Re: Where is decorator in this example code? fl <rxjwg98@gmail.com> - 2015-11-14 06:46 -0800
        Re: Where is decorator in this example code? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 09:08 -0700

csiph-web