Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.unit0.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '%s"': 0.07; "'a'": 0.07; '"a"': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; '"b"': 0.16; "'b'": 0.16; '(resulting': 0.16; 'a()': 0.16; 'a(object):': 0.16; 'b()': 0.16; 'classes:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'wed,': 0.16; '>>>': 0.18; 'all,': 0.21; 'question': 0.27; 'header:X-Complaints- To:1': 0.28; 'trouble': 0.28; 'question:': 0.29; 'subject:other': 0.29; 'skip:_ 10': 0.29; 'van': 0.29; 'class': 0.29; 'print': 0.32; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'ana': 0.91; 'dennis': 0.91; 'received:108': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: moving methods from class to instance of other class Date: Thu, 28 Jun 2012 14:15:05 -0400 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-68-178-241.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1340907329 news.xs4all.nl 6840 [2001:888:2000:d::a6]:43804 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24630 On Wed, 27 Jun 2012 23:59:22 -0700 (PDT), lars van gemerden declaimed the following in gmane.comp.python.general: > Hi all, > > I have some trouble with the following question: Let say i have the > following classes: > > class A(object): > def __init__(self): > self.name = 'a' > def do(self): > print 'A.do: self.name =', self.name > > class B(object): > def __init__(self): > self.name = 'b' > > > > The question is: How do i move the 'do' method from A to b (resulting > in printing "A.do: self.name = b")? >>> class A(object): ... def __init__(self): ... self.name = "a" ... def do(self): ... print "A.do: self.name = %s" % self.name ... >>> class B(A): ... def __init__(self): ... super(B, self).__init__() ... self.name = "b" ... >>> anA = A() >>> aB = B() >>> anA.do() A.do: self.name = a >>> aB.do() A.do: self.name = b >>> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/