[Tutor] Overloading + factoring

JoanCarles p Casasín joanca@typerware.com
Fri, 3 Dec 1999 12:46:04 +0100


FFlores wrote:

>A question about class methods:
>Can you overload the definition of a method,
>especially __init__?

Yes it is:

class foo:
	def __init__(self):
		print '__init__ from foo'
		
	def printanother(self):
		print 'a foo method'
	
	def printsame(self):
		print 'same for both classes'
		
a = foo()
a.printanother()
a.printsame()

class fee (foo):
	def __init__(self):
		print '__init__ from fee (overloaded)'
	
	def printanother(self):
		print 'a fee method (overloaded)'
		
b = fee()
b.printanother()
b.printsame()


I hope it helps,


JoanCarles


:::!!!:::
joanca@typerware.com

http://www.typerware.com