Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98803
| X-Received | by 10.31.165.148 with SMTP id o142mr2294006vke.7.1447503034679; Sat, 14 Nov 2015 04:10:34 -0800 (PST) |
|---|---|
| X-Received | by 10.50.78.164 with SMTP id c4mr164470igx.4.1447503034647; Sat, 14 Nov 2015 04:10:34 -0800 (PST) |
| Path | csiph.com!xmission!news.glorb.com!i2no2161924igv.0!news-out.google.com!l1ni4078igd.0!nntp.google.com!i2no2161920igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sat, 14 Nov 2015 04:10:33 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=50.100.117.144; posting-account=SZ_svQkAAACWRFG2bDA-zgq8ILyl4-vo |
| NNTP-Posting-Host | 50.100.117.144 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <3800f31d-e570-4492-9dcf-58105c140b2b@googlegroups.com> (permalink) |
| Subject | Where is decorator in this example code? |
| From | fl <rxjwg98@gmail.com> |
| Injection-Date | Sat, 14 Nov 2015 12:10:34 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:98803 |
Show key headers only | View raw
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?
Thanks,
......
def p_decorate(func):
def func_wrapper(self):
return "<p>{0}</p>".format(func(self))
return func_wrapper
class Person(object):
def __init__(self):
self.name = "John"
self.family = "Doe"
@p_decorate
def get_fullname(self):
return self.name+" "+self.family
my_person = Person()
print my_person.get_fullname()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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