python - 为什么列表/字典理解在类中具有不同的范围?
问题描述
执行失败:
class Data:
foo = 12
bar = 42
baz = [i * bar for i in range(foo)]
执行此工作:
foo = 12
bar = 42
baz = [i * bar for i in range(foo)]
我发现这个问题似乎是本质上相同问题的更复杂版本,但没有明确答案为什么范围似乎在类 + dict / 列表理解中发生变化。
解决方案
推荐阅读
- ruby - Rspec mongoid - 测试嵌入式文档回调(after_save)
- c# - 将存储在项目文件夹中的图像添加到 Microsoft Interop Word 文档
- laravel - 流明实时 API
- google-apps-script - 尝试将 Google 表格 moveTo 脚本转换为 copyTo 脚本
- javascript - 查找邮政编码 | 使用谷歌地图地理编码反向的邮政编码
- apache-spark - 第一次执行 spark 大约需要 13 秒,但第二次,每隔一次执行需要 3.5 秒
- python - 在python中获取特定包的依赖树
- c# - 如何检查 API 请求中的价值声明 (ASP.NET Core 2.2)
- python - Python3:如何将 PRINTed 项目转换为变量,以及如何将 VARIABLE 打印到 Excel 中的单元格中?
- mongodb - mongoDB 找到一个引发警报的查询