Python 2.7 如何从字典中调用函数

Python 2.7 如何从字典中调用函数,python-2.7,dictionary,Python 2.7,Dictionary,我试图从字典中调用一个函数,但不断收到一条错误消息,指出第11行未定义name:one\u 1\u 1 我不知道如何解决这个问题,我已经在这个网站上四处查看了一下,认为我做的每件事都是正确的,但是当我尝试运行我的程序时,这个错误会不断地被张贴出来。 请帮忙 def choice(): choice = raw_input(prompt) choice.lower() def wall(): print "You ran into a wall." print "

我试图从字典中调用一个函数,但不断收到一条错误消息,指出第11行未定义
name:one\u 1\u 1

我不知道如何解决这个问题,我已经在这个网站上四处查看了一下,认为我做的每件事都是正确的,但是当我尝试运行我的程序时,这个错误会不断地被张贴出来。 请帮忙

def choice():
    choice = raw_input(prompt)
    choice.lower()

def wall():
    print "You ran into a wall."
    print "Try again... "

def really():
    print "Don't you know how to give directions?"
    print "Try again..."

prompt = "> "
n = "north"
s = "south"
e = "east"
w = "west"
loop = True

i = {
    #first number represents the row 
    #second number represents the column
    11: one_1_1, 
    12: one_1_2,
    21: one_2_1
}


def one_1_1():
    "You are in a dark room"
    "Which way do you go?"
    left_corner(11)

def one_2_1():
    print "I am what you get when"
    print "you go south"

def one_1_2():
    print "This is what you get when"
    print "You go east"

def left_corner(position):
    choice()
    while loop == True:

        if choice == n:
            wall()
            i[position]()

        elif choice == s:
            i[position + 10]()

        elif choice == e:
            i[position + 1]()

        elif choice == w:
            wall()
            i[position]()
        else: 
            really()

one_1_1()

在定义函数之前,不能将其放入字典中。将
i={…}
移动到其中函数定义的下方。谢谢。我知道这很简单,我只是不明白在定义函数之前,你不能把它们放到字典里。将
i={…}
移动到其中函数定义的下方。谢谢。我知道这件事很简单,只是我没有看到