Eclipse 中的 PyDev 交互式 Python Shell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18326541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PyDev Interactive Python Shell in Eclipse
提问by Joohwan
I've been using Wing IDE for python programming and I am trying to switch to Eclipse, PyDev.
我一直在使用 Wing IDE 进行 python 编程,我正在尝试切换到 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:
当我在 Wing IDE 中运行我的代码时,在完成执行后,控制台会立即返回交互式 shell,我可以继续进行测试,但我不知道如何在 Eclipse 中执行此操作。我不确定我是否正确描述了我的问题,所以我将使用一个例子:
Let's say I had a simple source code that looked like this (e.g. test.py):
假设我有一个看起来像这样的简单源代码(例如 test.py):
print("hello")
When I run this in Wing IDE by clicking that green arrow, the console would look like this after execution:
当我通过单击绿色箭头在 Wing IDE 中运行它时,控制台在执行后看起来像这样:
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:
我可以继续在 shell 上做任何事情,它会知道我的代码(定义的函数等)。但是当我在 Eclipse 中做同样的事情时,控制台看起来就像这样:
hello
and I have to click "Remove All Terminated Launches" button to go back to the shell.
我必须单击“删除所有终止的启动”按钮才能返回外壳。
Can this be done in Eclipse?
这可以在 Eclipse 中完成吗?
回答by Fabio Zadrozny
What you want to use is the interactive console in PyDev(not the regular output when you do a run).
您要使用的是PyDev 中的交互式控制台(而不是运行时的常规输出)。
To use it do: Ctrl+Alt+Enter.
要使用它,请执行以下操作:Ctrl+ Alt+ Enter。
Note that if you're in the middle of a debug session, you can also use the debug session consoleto interact with the program.
请注意,如果您正在调试会话中,您还可以使用调试会话控制台与程序进行交互。
It can also be created from the UI in the console view as shown below:
它也可以从控制台视图中的 UI 创建,如下所示:
[
[
回答by Prahalad Deshpande
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 addedto the list of already opened consoles. Hence you can switch back to a previously open console by using the Display Selected Consoleoption within the console view ( refer herefor a list of all the available console options).
据我所知,我们可以在 Eclipse 中打开多个特定类型的控制台。每当我们在 PyDev 中运行脚本时,它都会打开一个新的控制台,将脚本的输出(包括错误输出)打印到该控制台。然而,这只是一个添加到已打开控制台列表中的新控制台。因此,您可以使用控制台视图中的“显示选定的控制台”选项切换回以前打开的控制台(请参阅此处获取所有可用控制台选项的列表)。
What does this mean?
这是什么意思?
You can open a new Python interpretor console using the Open Consoleoption 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 Consoleoption.
您可以使用Eclipse 控制台视图中的打开控制台选项打开一个新的 Python 解释器控制台。您可以定义您的方法并在该控制台中使用解释器。您现在运行在 PyDev 编辑器中打开的 Python 脚本。打开一个新的控制台,您可以在其中看到脚本的输出(也包括错误输出)。现在,如果您想返回交互式控制台,只需从Display Console选项中选择您之前打开的 Python Interpretor 控制台。
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.
就我个人而言,我喜欢这种设计,其中脚本的输出不会与您在 Python 控制台上的实验性逗留混合和混乱。这反过来导致对各种 Python 环境中发生的事情的清晰、清晰和简洁的视图。
Hope this bit of information helps.
希望这些信息有帮助。