Inheritance problem ?

tooper googlenews at
Wed Aug 24 12:34:36 CEST 2005

Hello all,

I'm trying to implement a common behavior for some object that can be
read from a DB or (when out of network) from an XML extract of this DB.
I've then wrote 2 classes, one reading from XML & the other from the
DB, both inheritating from a common one where I want to implement
several common methods.
Doing this, I've come to some behaviour I can't explain to myself,
which I've reproduced in the example bellow :


class myfather:
	def __repr__(self):
		return "\t a="+self.a+"\n\t b="+self.b

class mychilda(myfather):
	def __init__(self,a):
		self.a= a
	def __getattr__(self,name):
		return "Undefined for mychilda"

class mychildb(myfather):
	def __init__(self,b):
		self.b= b
	def __getattr__(self,name):
		return "Undefined for mychildb"

a= mychilda("a")
b= mychildb("b")

print "a:\n"+str(a)
print "b:\n"+str(b)


I was expecting to get :

   a= a
   b= Undefined for mychilda
   a= Undefined for mychildb
   b= b

but I get the following error :

File "/home/thierry/", line 20, in ?
    print "a:\n"+str(a)
TypeError: 'str' object is not callable

Could someone explain me what I missed ?

Thanks in advance !

More information about the Python-list mailing list