There’s a problem in Pydev 2.5 and Python 3.2 with trying to load the module contents “into” the interactive console: when you hit Ctrl+Alt+Enter, Pydev fires execfile(filename) instead of exec(compile(open(filename).read(), filename, ‘exec’), globals, locals) – the latter being execfile()’s replacement in Python 3+…
So, how to change this behaviour?
ETA: to be a bit more concrete, things go like this: I create a new PyDev Module, say ‘test.py’, write some simple function def f(n): print(n), hit Ctrl+Alt+Enter, then I select “Console for currently active editor” and Python 3.2 interpreter, interactive console wakes up, and then I get this:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
PyDev console: using default backend (IPython not available).
C:\Program Files (x86)\Python\3.2\python.exe 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]
>>> execfile('C:\\testy.py')
>>> f(1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'f' is not defined
As you can see, it still uses execfile() instead of exec(), that replaced it in Python 3+…
EDIT:
The actual problem is that the execfile is not getting the proper globals in the PyDev redefinition. So, if the execfile did execfile(‘my_file’, globals()), it would work… I’ll change the implementation of PyDev so that if the globals is not passed, it’ll do:
(you can fix that in your local install at plugins/org.python.pydev_XXX/PySrc/_pydev_execfile.py and it should work — please let me know if it doesn’t).
INITIAL ANSWER:
That’s not possible, but PyDev does redefine execfile when you’re in its console on Python 3, so, it should still work… is that not working for you for some reason?
Also, the replacement: exec(compile(open(filename).read(), filename, ‘exec’), globals, locals) is broken for some situations in Python 3.
The actual redefinition (which should work in all situations and is available in PyDev) is: