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)
myglass = glasschoice()
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:
AttributeError: RedGlassCost instance has no __call__ method
What is this trying to tell me? Or is that irrelevant as I would be
better off trying some other approach altogether?
_______________________________________________
Tutor maillist - [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
I have guessed your meaning by that code. Try the following:
glasstype={\
'Red':RedGlassCost,\
'Blue':BlueGlassCost,\
'Yellow':YellowGlassCost}
# RedGlassCost ... are types.FunctionType
myglass=glasstype[glass]()
_______________________________________________
Tutor maillist - [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor