[Tutor] AttributeError: instance has no __call__ method

Max Noel maxnoel_fr at yahoo.fr
Thu Dec 16 04:28:47 CET 2004

On Dec 16, 2004, at 04:20, Max Noel wrote:

>> def glass_type(glasstype):
>> 	if glasstype == 'Red':
>> 		myglass = RedGlassCost()
>> 	elif glasstype == 'Blue':
>> 		myglass = BlueGlassCost()
>> 	elif glasstype == 'Yellow':
>> 		myglass = YellowGlassCost()
>> 	return myglass
>> glasschoice = glass_type(glass)
>> myglass = glasschoice()
> 	Can we see your code for the *GlassCost classes?

	Nevermind, I just figured out the problem. RedGlassCost() returns an 
instance of the RedGlassCost class, whereas RedGlassCost is the class 
itself. Thus, you need to remove the parentheses either in the 
def_glasstype function (you then return a class, affect it to 
glasschoice and then create an instance of it by instanciating 
glasschoice) or in your last line (glass_type returns an instance of 
the class you want).

-- Max

More information about the Tutor mailing list