首页 > 解决方案 > 赋值不总是变量吗?

问题描述

我正在尝试在 Pycharm 中调试一些 Python3.8 代码。

代码最初分配一个值,如下所示:

self.stats.game_active = False

并在游戏开始后进行如下修改:

self.stats.game_active = True

当我运行调试器时,我看不到当前值是 True 还是 False,因为我没有在变量列表中看到该值。

我找错地方了吗?我以为我正在使用一个变量。我不是吗?如果它不是变量,它叫什么?如果它是一个变量,我如何让它显示在调试器的变量列表中?

克利波维奇

可能有帮助的其他信息:

class GameStats:
    """Track statistics for Alien Invasion."""

    def __init__(self, ai_game):
        """Initialize statistics."""
        self.settings = ai_game.settings
        self.reset_stats()

        # Start Alien Invasion in an inactive state.
        self.game_active = False

def __init__(self):
    """Initialize the game and create game resources."""
    pygame.init()
    self.settings = Settings()

    # Create an instance to store game statistics
    self.stats = GameStats(self)



 def _start_game(self):
        # Reset the game statistics.
        self.stats.reset_stats()
        self.stats.game_active = True

标签: pythonvariablesdebuggingpycharm

解决方案


您是否尝试将变量添加到观察列表?

据我所知,这应该可以让您始终看到变量的值。

- 在 Watches 窗格中,单击 New Watch 按钮 New Watch 或按 Insert。

- 在“变量”窗格中选择一项或多项并将它们拖到“监视”窗格中。

或者

- 右键单击​​编辑器中的项目并选择添加到手表。


推荐阅读