trouble understanding inheritance...

KraftDiner bobrien18 at yahoo.com
Wed Aug 16 14:33:03 EDT 2006


This is not working the way I think it should....
it would appear that fromfile and getName are calling the baseClass
methods which are
simple passes.... What have I done wrong?

class baseClass:
	def __init__(self, type):
		if type == 'A':
			self = typeA()
		else:
			self = typeB()
	def fromfile(self):
		pass
	def getName(self):
		pass

class typeA(baseClass):
	def __init__(self):
		self.name='A'
		print 'typeA init'
	def fromfile(self):
		print 'typeA fromfile'
	def getName(self):
		print self.name

class typeB(baseClass):
	def __init__(self):
		self.name='B'
		print 'typeB init'
	def fromfile(self):
		print 'typeB fromfile'
	def getName(self):
		print self.name

a = baseClass('A')
a.fromfile()
a.getName()

b = baseClass('B')
b.fromfile()
b.getName()

log:
typeA init
typeB init




More information about the Python-list mailing list