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


Groups > comp.lang.python > #72989

Re: Decorating one method of a class C with another method of class C?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'socket': 0.07; 'dan': 0.09; 'subject:method': 0.09; 'cc:addr:python-list': 0.11; '"list': 0.16; 'finney': 0.16; 'merely': 0.16; 'operation,': 0.16; 'simple.': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'example': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; 'message- id:@mail.gmail.com': 0.30; 'writes:': 0.31; 'class': 0.32; 'probably': 0.32; '(i.e.': 0.33; 'actual': 0.34; "i'd": 0.34; 'subject:with': 0.35; 'connection': 0.35; 'operations': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:one': 0.36; 'useful': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'operating': 0.37; 'ben': 0.38; 'configured': 0.38; 'simple': 0.61; 'making': 0.63; 'improvement': 0.84; 'why?': 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 :cc:content-type; bh=EskVnUUHgSffFJmjn7S164a0m+3LQ3Gj4E0qK4NbMZ4=; b=Q158nJSk1/I6CasHuSwlvGsKWrpuC9H9jS3iEWWoA0HqHNB/f4WdAYWNekyCue9qrS TYlIgi0KOrOFY7Ut6Vcs2cgDGi/qCnPGbEbMj7dUA/WRmszcm2F+CqnVgLgtBy2gv1Nv uJur+GlZFtiPQgjVmV1kRXQKHvITKSrjEz833FJQ6TAzeRlQEw4rkeBX5jRz861JDuWf wnRx9eN3m6KQdaeY5KsHYlqM91q31Qz9KzepW7R1xi1lF6qb8DyX32HatYRuLy0zwvKq VBhndS76iTQ/jQbChSjKARmnWJZ6YsjjkBzpzho1snNcdFVUPPIXX597flbmT9WX0Wu0 33wQ==
MIME-Version 1.0
X-Received by 10.236.191.132 with SMTP id g4mr7358642yhn.32.1402250655219; Sun, 08 Jun 2014 11:04:15 -0700 (PDT)
In-Reply-To <85lht91s30.fsf@benfinney.id.au>
References <CAGGBd_pM5DGp85LVfeQgYwqS8DU8nuQL8Q8G5EzfQ5BX26fa-w@mail.gmail.com> <85lht91s30.fsf@benfinney.id.au>
Date Sun, 8 Jun 2014 11:04:15 -0700
Subject Re: Decorating one method of a class C with another method of class C?
From Dan Stromberg <drsalists@gmail.com>
To Ben Finney <ben@benfinney.id.au>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10897.1402251131.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402251131 news.xs4all.nl 2899 [2001:888:2000:d::a6]:53877
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72989

Show key headers only | View raw


On 6/6/14, Ben Finney <ben@benfinney.id.au> wrote:
> Dan Stromberg <drsalists@gmail.com> writes:
>
>> Is there a way of decorating method1 of class C using method2 of class
>> C?
>
> Can you give a concrete example (i.e. not merely hypothetical) where
> this would be a useful feature (i.e. an actual improvement over the
> absence of the feature), and why?

I have a class that's operating on a socket.

I'd like to have simple operations on that socket like "list
configured hosts", "allow connection to host", etc.  And I'd like them
to be decorated with "reconnected_to_server_if_needed".

I'll probably end up putting a try/except in each simple operation,
making them a bit less simple.

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


Thread

Re: Decorating one method of a class C with another method of class C? Dan Stromberg <drsalists@gmail.com> - 2014-06-08 11:04 -0700

csiph-web