Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29456
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; '"""': 0.05; 'debugging': 0.05; 'modify': 0.05; 'result,': 0.05; 'decorator': 0.07; 'wrapper': 0.07; 'python': 0.09; '#print': 0.09; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:not': 0.11; 'mine.': 0.16; 'reedy': 0.16; 'syntax.': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'input': 0.18; 'variable': 0.20; 'versions': 0.20; 'decorators': 0.22; 'doc': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'invoke': 0.29; 'returned': 0.30; 'function': 0.30; 'button': 0.30; '(and': 0.32; 'info': 0.32; 'print': 0.32; 'traditional': 0.33; 'know.': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'from:addr:googlemail.com': 0.35; 'mapping': 0.35; 'received:209.85': 0.35; "i'll": 0.36; 'too': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'things': 0.38; 'instead': 0.39; 'save': 0.61; 'show': 0.63; 'troubles': 0.84; 'try,': 0.84; 'mistake': 0.91; 'trouble.': 0.91 |
| Newsgroups | comp.lang.python |
| Date | Tue, 18 Sep 2012 16:47:44 -0700 (PDT) |
| In-Reply-To | <mailman.718.1347655202.27098.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| References | <f7e2ec78-2c4a-402e-9a90-6cf0e7e55a54@c8g2000pbe.googlegroups.com> <732807993.849639.1347614902104.JavaMail.root@sequans.com> <mailman.718.1347655202.27098.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 123.192.32.215 |
| MIME-Version | 1.0 |
| Subject | Re: Decorators not worth the effort |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| 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.894.1348012073.27098.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1348012073 news.xs4all.nl 6843 [2001:888:2000:d::a6]:35534 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:29456 |
Show key headers only | View raw
Terry Reedy於 2012年9月15日星期六UTC+8上午4時40分32秒寫道:
> 2nd try, hit send button by mistake before
>
>
>
> On 9/14/2012 5:28 AM, Jean-Michel Pichavant wrote:
>
>
>
> > Decorators are very popular so I kinda already know that the fault is
>
> > mine. Now to the reason why I have troubles writing them, I don't
>
> > know. Every time I did use decorators, I spent way too much time
>
> > writing it (and debugging it).
>
>
>
> You are writing parameterized decorators, which require inverted
>
> currying of the wrapper maker. Perhaps that is why you have trouble. As
>
> I showed in response to Cameron, it may be easier to avoid that by using
>
> a traditional post-def wrapping call instead of decorator syntax.
>
>
>
> --
>
> Terry Jan Reedy
I'll give another example to show the decorators in python in
versions above 2.4 .
# a general function with the variable input : def fname( *argc, **argn)
# a deco is a mapping from an input funtion to another function
def deco( fn, *list_in, **dict_in): # use list_in and dict_in to modify fn
""" deco wrapper """ # deco.__doc__
#print list_in, dict_in, " in the deco"
def wrapper( fn, *argc, **argan): # to be returned as a function
# do things one wants before calling fn
result=fn(*argc, **argn) # call the original, save the result
# do things after calling fn
return result
# enhance the wrapper and get info of fn
wrapper.__doc__=fn.__doc__
# enhance wrapper with result, fn, list_in, dict_in
#....
return wrapper
def f1():
""" doc of f1"""
print "inside f1"
f2=deco(f1, 2,3,4,5,6, MSG="deco f1 to f2")
f2() # invoke the decorated function from f1
# For a deco maps a deco to another deco can be done similarly
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Python presentations Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-09-13 19:54 +0200
Re: Python presentations Alister <alister.ware@ntlworld.com> - 2012-09-13 18:18 +0000
Decorators not worth the effort alex23 <wuwei23@gmail.com> - 2012-09-13 18:58 -0700
Re: Decorators not worth the effort Cameron Simpson <cs@zip.com.au> - 2012-09-14 12:12 +1000
Re: Decorators not worth the effort alex23 <wuwei23@gmail.com> - 2012-09-13 20:25 -0700
Re: Decorators not worth the effort Dieter Maurer <dieter@handshake.de> - 2012-09-14 08:40 +0200
Re: Decorators not worth the effort Terry Reedy <tjreedy@udel.edu> - 2012-09-14 16:29 -0400
Re: Decorators not worth the effort Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-15 09:13 +0200
Re: Decorators not worth the effort alex23 <wuwei23@gmail.com> - 2012-09-16 17:38 -0700
Re: Decorators not worth the effort Terry Reedy <tjreedy@udel.edu> - 2012-09-14 16:31 -0400
Re: Decorators not worth the effort Terry Reedy <tjreedy@udel.edu> - 2012-09-14 16:37 -0400
Re: Decorators not worth the effort 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-18 16:47 -0700
Re: Decorators not worth the effort 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-18 16:47 -0700
Re: Decorators not worth the effort Terry Reedy <tjreedy@udel.edu> - 2012-09-14 16:33 -0400
Re: Decorators not worth the effort Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-14 15:16 -0600
Re: Decorators not worth the effort Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-14 23:39 +0000
Re: Decorators not worth the effort 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-15 02:45 -0700
Re: Decorators not worth the effort Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-15 06:04 -0400
Re: Decorators not worth the effort 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-15 07:18 -0700
Re: Decorators not worth the effort Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-18 14:16 +0200
Re: Decorators not worth the effort 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-15 07:18 -0700
Re: Decorators not worth the effort Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-14 23:42 -0400
Re: Decorators not worth the effort "Dieter Maurer" <dieter@handshake.de> - 2012-09-15 08:31 +0200
csiph-web