仅使用大写字母命名时,变量在 Spyder 的变量资源管理器中不可用

Variable not available at Spyder's Variable Explorer when naming it with upper case only

我在使用 Spyder 时遇到以下问题:

如果我只用大写字母命名一个变量,它不会显示在变量资源管理器中 window。

例如,如果我将变量命名为: Var = 1,它在变量资源管理器中。

否则,如果我这样命名: VAR = 1,此处未显示。

有人知道这是为什么吗?有什么办法可以解决吗?

(ps:拜托,我知道我可以 "not name them like that",但这不是我要问的)

谢谢

我是 Python 和 Spyder 的新手,但我想我可以帮助你。根据PEP 8 -- Style Guide for Python Code:

"Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL".

我猜想Spyder使用了这个约定。如果是这种情况,则变量资源管理器不支持常量。 The Spyder 2.3 documentation 有支持的对象类型列表,不包括常量:

  1. Pandas 数据帧和时间序列
  2. NumPy 数组和矩阵
  3. PIL/Pillow 图片
  4. 日期时间日期
  5. 整数
  6. 花车
  7. 复数
  8. 列表
  9. 词典
  10. 元组
  11. 字符串

希望对您有所帮助。

更新: 我刚刚在变量资源管理器右侧的垂直栏中找到了一个选项图标,它允许您 enable/disable 大写变量。