[Tutor] Associate functinos with Dictionary/Class Usage

Luke Jordan luke.jordan at gmail.com
Thu Apr 7 23:45:34 CEST 2005


Hi! 

My questions arose from reading the "Help with Classes" email that's
been on this list for the past couple of days.

I'm also writing a text game, but mine is puzzle not adventure.
Anyway, someone mentioned that you can key words to a dictionary to
have user input run functions.

I am looking for a little clarification of how exactly this would work.

1. How do I associate a function to a dict key?

2. If I do this, do objects have to be built from classes with
appropriate attributes?

Right now I am using a handful of methods that are called in if statements:

def takeItem(item):
    items.append(item)
    print "You took the", item

action = raw_input(">>> ")
if action == "take":
    what = raw_input("What do you want to take? ")
    takeItem(takeWhat)
elif action == "drink":
    etc.

Thanks!

Luke

-- 
"Scalpel....blood bucket....priest....next patient."


More information about the Tutor mailing list