集合推导式在 Pydev (Python) 上不起作用

发布于 2024-09-16 13:38:56 字数 257 浏览 4 评论 0原文

{x for x in range(10)}

在 IDLE 上完美运行,但是当我在 eclipse 中尝试(使用 Pydev 插件)时,出现语法错误:

未定义的变量:x

是因为 Pydev 不支持集合推导式还是其他原因?我该怎么做才能使这项工作成功? (这只是一个不起作用的例子。所有集合推导式都不适合我)。

(我使用的是Python 3)

{x for x in range(10)}

works perfectly on IDLE, but when I try this in eclipse (with Pydev plugin) I get a syntax error:

Undefined variable: x

Is it because Pydev doesn't support set comprehensions or something? What can I do to make this work?
(This was just one example that doesn't work. All set comprehensions don't work for me).

(I'm using Python 3)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苯莒 2024-09-23 13:38:59

您可以找出您正在使用的 Python 版本

import sys
sys.stdout.write( sys.version )

You can find out which version of Python you are using with

import sys
sys.stdout.write( sys.version )
花开柳相依 2024-09-23 13:38:58

这是 PyDev 中的一个错误;在这种情况下,忽略编辑器的警告并执行代码:它将起作用。

我经常这么说,PyDev 并不完美,但它已经足够好了!

This is a bug in PyDev; in this case ignore the editor's warning and execute the code: it will work.

I get this a lot, PyDev isn't perfect but it's good enough!

贪了杯 2024-09-23 13:38:58

确保 Pydev 配置为使用 Python 3。

Make sure that Pydev is configured to use Python 3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文