Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16936
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <dihedral88888@googlemail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'way:': 0.05; 'subject:Python': 0.05; 'happily': 0.07; 'python': 0.08; 'false,': 0.09; 'func': 0.09; 'reply-to:addr:comp.lang.python': 0.09; 'to:addr:comp.lang.python': 0.09; 'output': 0.10; 'def': 0.13; 'anymore.': 0.16; 'assembly,': 0.16; 'aye': 0.16; 'comma,': 0.16; 'erlang.': 0.16; 'handy': 0.16; 'lambda': 0.16; 'logic.': 0.16; 'magic.': 0.16; 'cc:addr:python-list': 0.16; "wouldn't": 0.17; 'wrote:': 0.18; '>>>': 0.18; 'functions,': 0.18; 'this?': 0.19; 'cc:no real name:2**0': 0.20; 'maybe': 0.21; 'dec': 0.22; 'header :In-Reply-To:1': 0.22; 'statement': 0.23; 'cc:2**0': 0.24; 'consist': 0.24; 'keyword': 0.24; 'code': 0.25; 'helpful': 0.26; "i'm": 0.26; 'function': 0.27; '(this': 0.28; 'skip:( 40': 0.28; 'exit': 0.29; 'true,': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'example': 0.29; 'decorators': 0.30; 'logic': 0.30; 'chris': 0.30; 'does': 0.32; 'thu,': 0.32; 'implement': 0.32; "isn't": 0.33; 'header:User-Agent:1': 0.33; 'there': 0.33; 'it?': 0.33; 'done': 0.34; 'someone': 0.34; 'from:addr:googlemail.com': 0.34; '(including': 0.34; 'function.': 0.34; 'nested': 0.34; 'skip:@ 10': 0.34; 'however,': 0.36; 'uses': 0.36; 'thursday,': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'entry': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'doing': 0.38; 'using': 0.38; 'received:209.85': 0.38; 'put': 0.38; 'why': 0.39; "it's": 0.40; 'missing': 0.40; 'received:209': 0.40; 'once': 0.60; 'more': 0.61; 'type': 0.61; '2011': 0.61; 'your': 0.61; 'saturday,': 0.64; 'high': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:googlegroups.com': 0.74; 'subject:!!!': 0.76; 'care,': 0.77; '10:22': 0.84 |
| Newsgroups | comp.lang.python |
| Date | Fri, 9 Dec 2011 16:21:11 -0800 (PST) |
| In-Reply-To | <17457040.1331.1323455329763.JavaMail.geo-discussion-forums@pret21> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=1.168.131.48; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| References | <29996186.628.1323328726122.JavaMail.geo-discussion-forums@prfb7> <jbpu9j$1af$1@r03.glglgl.gl> <jbq6li$p9o$1@dough.gmane.org> <mailman.3408.1323344595.27778.python-list@python.org> <17457040.1331.1323455329763.JavaMail.geo-discussion-forums@pret21> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| MIME-Version | 1.0 |
| Subject | Re: I love the decorator in Python!!! |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | comp.lang.python@googlegroups.com |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.3485.1323476480.27778.python-list@python.org> (permalink) |
| Lines | 54 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1323476480 news.xs4all.nl 6878 [2001:888:2000:d::a6]:42400 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16936 |
Show key headers only | View raw
On Saturday, December 10, 2011 2:28:49 AM UTC+8, 88888 Dihedral wrote:
> On Thursday, December 8, 2011 7:43:12 PM UTC+8, Chris Angelico wrote:
> > On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Aye <kmic...@gmail.com> wrote:
> > > I am still perplexed about decorators though, am happily using Python for
> > > many years without them, but maybe i am missing something?
> > > For example in the above case, if I want the names attached to each other
> > > with a comma, why wouldn't I just create a function doing exactly this? Why
> > > would I first write a single name generator and then decorate it so that I
> > > never can get single names anymore (this is the case, isn't it? Once
> > > decorated, I can not get the original behaviour of the function anymore.
> >
> > The example given is a toy. It's hardly useful. However, there are a
> > number of handy uses for decorators; mostly, they consist of giving a
> > single simple keyword to a complicated set of logic. One example is
> > the @classmethod and @staticmethod decorators - the code to implement
> > them could be uglier than nested inline assembly, but you don't have
> > to care, because you just type "@staticmethod" in front of your def
> > statement and it does its magic.
> >
> > Here's a handy trick that I'm sure someone has done in a more sophisticated way:
> >
> > def trace(func):
> > if debugmode:
> > return lambda *a,**ka:
> > (print(">"+func.__name__),func(*a,**ka),print("<"+func.__name__))[1]
> > return func
> >
> > Then you put @trace in front of all your functions, and if debugmode
> > is False, nothing will be done - but set it to true, and you get
> > console output at the entry and exit of each function.
> >
> > >>> @trace
> > def test(x):
> > print("Test! "+x)
> > return 5
> >
> > >>> test("asdf")
> > >test
> > Test! asdf
> > <test
> > 5
> >
> > Again, it's helpful because it condenses all the logic (including the
> > 'debugmode' flag) down to a single high level directive: "Trace this
> > function".
> >
> > ChrisA
>
> I did use decorators to turn functions into iterables to be traced.
It is easy to use decorators in python to mimic those programs in Erlang.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-07 23:18 -0800
Re: I love the decorator in Python!!! Chris Rebert <clp2@rebertia.com> - 2011-12-08 00:04 -0800
Re: I love the decorator in Python!!! Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-12-08 09:59 +0100
Re: I love the decorator in Python!!! Chris Angelico <rosuav@gmail.com> - 2011-12-08 20:37 +1100
Re: I love the decorator in Python!!! K.-Michael Aye <kmichael.aye@gmail.com> - 2011-12-08 12:22 +0100
Re: I love the decorator in Python!!! Francesco Bochicchio <bieffe62@gmail.com> - 2011-12-09 04:00 -0800
Re: I love the decorator in Python!!! Chris Angelico <rosuav@gmail.com> - 2011-12-08 22:43 +1100
Re: I love the decorator in Python!!! Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-12-09 10:57 +0100
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-09 10:28 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-09 16:21 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-09 16:21 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 06:04 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 06:09 -0800
Re: I love the decorator in Python!!! alex23 <wuwei23@gmail.com> - 2011-12-11 19:35 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 06:09 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-10 06:04 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-09 10:28 -0800
Re: I love the decorator in Python!!! K.-Michael Aye <kmichael.aye@gmail.com> - 2011-12-08 17:24 +0100
Re: I love the decorator in Python!!! Chris Angelico <rosuav@gmail.com> - 2011-12-09 03:38 +1100
Re: I love the decorator in Python!!! alex23 <wuwei23@gmail.com> - 2011-12-08 21:02 -0800
Re: I love the decorator in Python!!! Robert Kern <robert.kern@gmail.com> - 2011-12-09 10:08 +0000
Re: I love the decorator in Python!!! alex23 <wuwei23@gmail.com> - 2011-12-11 19:36 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-11 20:51 -0800
Re: I love the decorator in Python!!! alex23 <wuwei23@gmail.com> - 2011-12-11 21:47 -0800
Re: I love the decorator in Python!!! 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-12 04:16 -0800
Re: I love the decorator in Python!!! Ethan Furman <ethan@stoneleaf.us> - 2011-12-11 23:47 -0800
Re: I love the decorator in Python!!! Robert Kern <robert.kern@gmail.com> - 2011-12-12 16:27 +0000
Re: I love the decorator in Python!!! alex23 <wuwei23@gmail.com> - 2011-12-12 16:46 -0800
Re: I love the decorator in Python!!! Andrew Berg <bahamutzero8825@gmail.com> - 2011-12-08 10:54 -0600
Re: I love the decorator in Python!!! Andrew Berg <bahamutzero8825@gmail.com> - 2011-12-08 10:55 -0600
Re: I love the decorator in Python!!! Ethan Furman <ethan@stoneleaf.us> - 2011-12-08 15:34 -0800
Re: I love the decorator in Python!!! Ethan Furman <ethan@stoneleaf.us> - 2011-12-08 15:56 -0800
csiph-web