[Tutor] AttributeError: instance has no __call__ method

Terry Carroll carroll at tjc.com
Thu Dec 16 04:19:56 CET 2004


On Wed, 15 Dec 2004, Marc Gartler wrote:

> Hi everybody,
> 
> Prior to this chunk of code 'glass' has been chosen from a list of 
> colors via user input, and I now want to have that choice connect to 
> one of several possible classes:
> 
> 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)

At this point, glasschoice is set to glass_type(glass), which in turn is 
something like RedGlassCost().

> AttributeError: RedGlassCost instance has no __call__ method

Right; it sounds like you're using RedGlassCost as a function, but it 
wasn't defined as a function.  Can you show us how RedGlassCost is 
defined?


> I've tried various approaches and keep getting different errors.  But 
> this one seems closest to my goal, as I know it is at least passing 
> 'glass' into the function:

My mother always told me to apologize after passing glass.





More information about the Tutor mailing list