python - 赋值不总是变量吗?
问题描述
我正在尝试在 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
解决方案
您是否尝试将变量添加到观察列表?
据我所知,这应该可以让您始终看到变量的值。
- 在 Watches 窗格中,单击 New Watch 按钮 New Watch 或按 Insert。
- 在“变量”窗格中选择一项或多项并将它们拖到“监视”窗格中。
或者
- 右键单击编辑器中的项目并选择添加到手表。
推荐阅读
- php - 在 Woocommerce 3 中使用 Product CRUD setter 方法
- maven - 使用命令行更改 maven surefire 报告目录
- python - python turtle 导致错误
- swift - CoreBluetooth XPC 连接无效错误和 Info.plist 添加
- vba - 使用 VBA 对屏蔽 URL 进行 Web 抓取
- encryption - 没有 IV 的 AES CTR - 多条消息的相同密钥 - 安全吗?
- c++ - cpprestsdk:无法解析 json 输入
- angular - 如何在 Angular Firebase 中处理 observables
- javascript - 将 v-bind 添加到动态添加的元素
- java - 文件路径 - 相对路径