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


Groups > comp.lang.python > #24630

Re: moving methods from class to instance of other class

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: moving methods from class to instance of other class
Date 2012-06-28 14:15 -0400
Organization > Bestiaria Support Staff <
References <c376d4cf-c888-4fa9-8d4c-032b80a43947@e20g2000vbm.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1617.1340907329.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, 27 Jun 2012 23:59:22 -0700 (PDT), lars van gemerden
<lars@rational-it.com> 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/

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


Thread

moving methods from class to instance of other class lars van gemerden <lars@rational-it.com> - 2012-06-27 23:59 -0700
  Re: moving methods from class to instance of other class Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-06-28 00:22 -0700
    Re: moving methods from class to instance of other class lars van gemerden <lars@rational-it.com> - 2012-06-28 01:14 -0700
  Re: moving methods from class to instance of other class Terry Reedy <tjreedy@udel.edu> - 2012-06-28 13:57 -0400
  Re: moving methods from class to instance of other class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-06-28 14:15 -0400

csiph-web