获得“未解决的参考”错误

时间:2016-08-18 10:32:59

标签: python-3.x reference pycharm

即使我向它发表声明,我仍然会收到“未解决的引用”错误。

verb_dict = {"say": say, "examine": examine}

错误发生在examine

之后
def examine(noun):
    if noun in GameObject.objects:
        return GameObject.objects[noun].get_desc()
    else:
        return "There is no {}".format(noun)

编码时我做错了吗?

我也在使用pycharm社区版。

2 个答案:

答案 0 :(得分:0)

我无法在PyCharm 2016中复制您的问题。我运行以下代码时没有问题:

class GameObject:
    class_name = ""
    objects = {}

    def __init__(self, name):
        self.name = name
        GameObject.objects[self.class_name] = self


def examine(noun):
    if noun in GameObject.objects:
        return GameObject.objects[noun].get_desc()
    else:
        return "There is no {}".format(noun)

print(examine('try'))

输出

>>> There is no try

答案 1 :(得分:0)

这是GameObject类。 我没有在那里看到问题。如果您需要更多信息,请告诉我。

class GameObject:
    class_name = ""
    desc = ""
    objects = {}
    def __init__(self, name):

        self.name = name
        GameObject.objects[self.class_name] = self