如何在Eclipse / Pydev中将Python源重新加载到控制台窗口?

时间:2022-08-06 20:25:02

In other Python IDEs (PythonWin and Idle) it's possible to hit a key and have your current source file window reloaded into the console. I find this useful when experimenting with a piece of code; you can call functions from the console interactively and inspect data structures there.

在其他Python IDE(PythonWin和Idle)中,可以点击一个键并将当前的源文件窗口重新加载到控制台中。在尝试使用一段代码时,我觉得这很有用;您可以交互地从控制台调用函数并检查那里的数据结构。

Is there a way to do this with Eclipse/Pydev?

有没有办法用Eclipse / Pydev做到这一点?

So far I've been making do with this hack in my source file:

到目前为止,我一直在我的源文件中使用这个hack:

def relo():
    execfile("/Path/To/Source.py", __builtins__)

I call relo() in the console after I save changes to the source. But I'd much rather just tap a key. I'm using pydev 1.4.7.2843.

在保存对源的更改后,我在控制台中调用relo()。但我更愿意点击一把钥匙。我正在使用pydev 1.4.7.2843。

This is somewhat related to this question, but I want to just reload the whole source file.

这与此问题有些相关,但我想重新加载整个源文件。

2 个解决方案

#1


You can do it with Ctrl+Alt+Enter on the latest Pydev for details on what Ctrl+Alt+Enter provides as it can do a number of things related to the interactive console.

您可以使用最新的Pydev上的Ctrl + Alt + Enter来执行此操作,以获取有关Ctrl + Alt + Enter提供的详细信息,因为它可以执行与交互式控制台相关的许多操作。

#2


Use the revert option on the File menu.

使用“文件”菜单上的“还原”选项。

You can bind a key to it in Windows > Preferences > General > Keys.

您可以在Windows>首选项>常规>键中将键绑定到它。

Edit:

The reload(module) function will update packages in the interactive console. It's built in for python 2.x and in the imp module for 3.x. Python docs link: http://docs.python.org/3.1/library/imp.html?#imp.reload

重载(模块)功能将更新交互式控制台中的包。它内置于python 2.x和imp模块中的3.x. Python文档链接:http://docs.python.org/3.1/library/imp.html?#imp.reload

Couldn't find a way to run it by hotkey, I'd like to know if you find a way.

无法找到通过热键运行它的方法,我想知道你是否找到了方法。

#1


You can do it with Ctrl+Alt+Enter on the latest Pydev for details on what Ctrl+Alt+Enter provides as it can do a number of things related to the interactive console.

您可以使用最新的Pydev上的Ctrl + Alt + Enter来执行此操作,以获取有关Ctrl + Alt + Enter提供的详细信息,因为它可以执行与交互式控制台相关的许多操作。

#2


Use the revert option on the File menu.

使用“文件”菜单上的“还原”选项。

You can bind a key to it in Windows > Preferences > General > Keys.

您可以在Windows>首选项>常规>键中将键绑定到它。

Edit:

The reload(module) function will update packages in the interactive console. It's built in for python 2.x and in the imp module for 3.x. Python docs link: http://docs.python.org/3.1/library/imp.html?#imp.reload

重载(模块)功能将更新交互式控制台中的包。它内置于python 2.x和imp模块中的3.x. Python文档链接:http://docs.python.org/3.1/library/imp.html?#imp.reload

Couldn't find a way to run it by hotkey, I'd like to know if you find a way.

无法找到通过热键运行它的方法,我想知道你是否找到了方法。