【问题标题】:Core from exercise 43 of Zed Shaw's Learning Python the hard way doesn't run?来自 Zed Shaw 的 Learning Python 练习 43 的核心内容很难运行?
【发布时间】:2013-08-04 20:06:14
【问题描述】:

他使用这个框架代码来勾勒他想要创建的游戏:

class Scene(object):

    def enter(self):
        pass


class Engine(object):

    def __init__(self, scene_map):
        pass

    def play(self):
        pass

class Death(Scene):

    def enter(self):
        pass

class CentralCorridor(Scene):

    def enter(self):
        pass

class LaserWeaponArmory(Scene):

    def enter(self):
        pass

class TheBridge(Scene):

    def enter(self):
        pass

class EscapePod(Scene):

    def enter(self):
        pass


class Map(object):

    def __init__(self, start_scene):
        pass

    def next_scene(self, scene_name):
        pass

    def opening_scene(self):
        pass


a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()

他说使用最后一段代码(最后三行)来运行代码并测试它是否有效。当我在 powershell 中运行它时,没有任何反应,我知道类不会运行,除非它们被调用(在这种情况下它们是正确的?)所以这应该运行吗?还是我应该填写更多?他说:

在这个文件中,您可以看到我只是复制了我想要的层次结构,然后在最后编写了一些代码来运行它,看看它是否都在这个基本结构中工作。在本练习的后面部分,您将填写此代码的其余部分,并使其与游戏描述相匹配。

【问题讨论】:

    标签: python class


    【解决方案1】:

    Pass staments 基本上是向程序员发出尚未实现功能的信号的一种方式,它们本质上就像在说“这里会有一些东西”。所以程序不应该运行,它只是一个草图。

    【讨论】:

    • pass 语句还允许有一些没有代码的块。检查有关它的文档(例如等待 InterruptException 的最小类或 while True
    • @Pawelmhm 哦,我明白了,我想知道那是什么意思,但他没有明确说。感谢您的快速响应。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2011-12-04
    相关资源
    最近更新 更多