PyDev Interactive Python Shell in Eclipse
Asked Answered
D

2

8

I've been using Wing IDE for python programming and I am trying to switch to Eclipse, PyDev.

When I run my code in Wing IDE, after finishing the execution the console goes right back to the interactive shell and I can continue on testing, but I don't know how to do this in Eclipse. I'm not sure if I am describing my problem properly so I'll use an example:

Let's say I had a simple source code that looked like this (e.g. test.py):

print("hello")

When I run this in Wing IDE by clicking that green arrow, the console would look like this after execution:

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate untitled-1.py]
hello
>>>>

And I can keep doing whatever on the shell and it would know my code (defined functions etc.). But when I do the same thing in Eclipse, the console would simply look like this:

hello

and I have to click "Remove All Terminated Launches" button to go back to the shell.

Can this be done in Eclipse?

Duckpin answered 20/8, 2013 at 3:32 Comment(0)
C
14

What you want to use is the interactive console in PyDev (not the regular output when you do a run).

To use it do: Ctrl+Alt+Enter.

Note that if you're in the middle of a debug session, you can also use the debug session console to interact with the program.

It can also be created from the UI in the console view as shown below:

[Create PyDev interactive console [1]

Chiastolite answered 22/8, 2013 at 18:38 Comment(6)
Oh my god I've been looking for this forever. Thanks!Duckpin
Just a couple more questions.. How would I run the code in interactive console without using the command Ctrl+Alt+Enter?Duckpin
on a mac it's cmd + alt + enter. still though, how can I keep sending stuff to the console or inspect dir() etc.? I mean I can't just say run because that will open a separate process and execute and then terminate the script.Fantasize
Is there a way to find this in a menu or through an icon? Just curious and interested for the sake of reference.Interference
I don't think this answers the question. In PyDev, Ctrl+Alt+Enter doesn't give the same behavior as running a script in Wing IDE.Miniskirt
Humm... it should be the same thing (although you need to have a shell open first -- Ctrl+Alt+Enter would be used to create the shell and then a second Ctrl+Alt+Enter would be used to run the file in the shell and afterwards you should be able to inspect your objects in the shell) -- check pydev.org/manual_adv_interactive_console.html for more details (F2 can also be used in PyDev to send contents line by line).Chiastolite
P
2

From what I know, we can open multiple consoles of a particular type in Eclipse. Whenever we run a script within PyDev, it opens a new console to which it prints the output from the script (including error output). However this is just a new console that is added to the list of already opened consoles. Hence you can switch back to a previously open console by using the Display Selected Console option within the console view ( refer here for a list of all the available console options).

What does this mean?

You can open a new Python interpretor console using the Open Console option within the Eclipse Console view. You can define your methods and play with the interpretor within that console. You now run a Python script that is open within the PyDev editor. A new console gets opened up where-in you see the output from the script (includes error output too). Now if you want to go back to the interactive console, you simply choose the Python Interepretor console that you opened previously from the Display Console option.

Personally, I like this design where-in the output from your script does not mingle and mess up with your experimental sojourns on the Python console. This in turn results in a crisp, clear and concise view of what is happening within the various python environments.

Hope this bit of information helps.

Postgraduate answered 20/8, 2013 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.