【问题标题】:Code fail with name is not defined error running with pydev but runs fine from terminalCode fail with name is not defined 使用 pydev 运行的错误,但从终端运行良好
【发布时间】:2021-04-01 14:48:32
【问题描述】:

代码不会从 pydev 控制台运行,但是当我在终端中启动 python 时运行良好

m = [{'x1': 8183.79980469, 'x2': 9113.79980469, 'y': None, 'side': 'LH'}, {'x1': 29723.09960938, 'x2': 30653.09960938, 'y': None, 'side': 'LH'}, {'x1': 30657.40039062, 'x2': 31587.40039062, 'y': None, 'side': 'LH'}, {'x1': 30657.4, 'x2': 31587.4, 'y': None, 'side': 'RH'}]
side = 'LH'
[i['x1'] for i in m if i['side'] == side]
Traceback (most recent call last):
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.1.0.202012051215/pysrc/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<console>", line 1, in <module>
  File "<console>", line 1, in <listcomp>
NameError: name 'side' is not defined

我在运行 eclipse 的 mac 上 版本:2020-12 (4.18.0) 版本号:20201210-1552, PyDev for Eclipse 8.1.0.202012051215 和 Python 3.8.0

我在这里缺少什么?我该如何解决?

【问题讨论】:

标签: python eclipse pydev


【解决方案1】:

你在说什么控制台?这是调试控制台还是交互式控制台?可以发截图吗?

请注意,我无法重现它(我在调试控制台和交互式控制台中都对其进行了测试):

请注意,如果您在方法中定义了其他内容,您可能会遇到@codewelldev 提到的 Python 问题 (https://stackoverflow.com/a/23032799/13911868)

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    相关资源
    最近更新 更多