views:

50

answers:

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)

+2  A: 

Make sure that Pydev is configured to use Python 3.

UncleZeiv
I guess it is configured because I use Python 3 features all the time. But still, how do I check if it's configured to use Python 3?
snakile
Checked. I use Python 3. What else can it be?
snakile
Window > Preferences > Pydev > Interpreter - Python
UncleZeiv
Can you paste the exact syntax error?
UncleZeiv
What happens if you run the code from the shell?
UncleZeiv
When I run this from the shell: {x for x in range(10)},that's the output: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
snakile
the syntax error is a warning in the editor or something you get when you run the script from pydev? In the first case, it apparently was a bug in Pydev fixed in release 1.4.3: http://mail.python.org/pipermail/python-announce-list/2009-February/007246.html
UncleZeiv
This is the syntax error: "undefined variable x"
snakile
A: 

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

import sys
sys.stdout.write( sys.version )
katrielalex
I use Python 3.1.2
snakile
+2  A: 

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!

Beau Martínez
Thanks. I don't like getting errors so I won't use the feature. I'll do this instead: set(x for x in range(10))
snakile
@beau: shouldn't this have been fixed in version 1.4.3, according to the changelog? If it isn't, maybe we should issue a bug report.
UncleZeiv