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


Groups > comp.lang.python > #43053

How to subclass a family

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.079
X-Spam-Evidence '*H*': 0.85; '*S*': 0.01; 'else:': 0.03; 'received:134': 0.05; 'subject:How': 0.10; 'def': 0.12; 'subclass': 0.16; 'code.': 0.18; 'header:User-Agent:1': 0.23; 'code': 0.31; 'class': 0.32; 'could': 0.34; 'classes': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'course': 0.61; 'such': 0.63; 'different': 0.65; 'here': 0.66; 'of:': 0.68; 'family': 0.73; 'pardon': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result Ap0IALKQYlGGuA9G/2dsb2JhbABRxFoEBIEehBI9FhgDAgECAVgIAogQnBiXO4kRj0CDKwOWdIVwix6DDQ
Date Mon, 08 Apr 2013 11:44:51 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130116 Icedove/10.0.12
MIME-Version 1.0
To python-list@python.org
Subject How to subclass a family
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
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>
Newsgroups comp.lang.python
Message-ID <mailman.278.1365414362.3114.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365414362 news.xs4all.nl 6937 [2001:888:2000:d::a6]:39560
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43053

Show key headers only | View raw


Here is the idea. I have a number of classes with the same interface.
Something like the following:

class Foo1:
    def bar(self, ...):
        work
    def boo(self, ...):
        do something
        self.bar(...)

What I want is the equivallent of:

class Far1(Foo1):
    def boo(self, ...)
        do something different
        if whatever:
            self.bar(...)
        else:
            Foo1.boo(self, ...)

Now of course I could subclass every class from the original family
from Foo1 to Foon but that would mean a lot of duplicated code. Is
there a way to reduce the use of duplicated code in such circumstances?

-- 
Antoon Pardon

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


Thread

How to subclass a family Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-04-08 11:44 +0200
  Re: How to subclass a family Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-09 02:52 +0000

csiph-web