I'm experimenting with OOP using the Critter Caretaker script from Python
Programming for the Absolute Beginner as my basis. I've noticed that a
dictionary/function combo is a great way to handle menus, and so I've
adapted the menu to read as:


selection = raw_input("Choice: ")
choices = {"0":quit, "1":crit.talk, "2":crit.eat, "3":crit.play}
choice = choices[selection]
choice()

so that I can call methods from a dictionary, instead of having an
excruciatingly long if structure. Unfortunately, the problem I'm running
into with this is that I can't pass any perimeters through the dictionary. I
can't figure out how, for example, I could have an option that calls
crit.eat(2) and another that calls crit.eat(4). The only thing I can think
of is going back to the if structure, but my instinct tells me that this is
a Bad Idea. What can I do?
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to