适用于 Python 的轻量级控制台/IDE?

发布于 2024-10-16 22:46:54 字数 648 浏览 9 评论 0原文

我经常在编码时使用 ipython (或常规 python shell)来测试 python 代码片段,它非常有用。但这样做的一个缺点是,如果我想测试一段多行代码,或者想在运行之前编写多行代码,那么“一行一行”地执行就不太方便。即使返回更改某些行也很麻烦,因为您必须重新键入其后面的所有代码。

我现在正在使用 Groovy,我发现它对这个问题有一个很好的解决方案: Groovy Console< /a>.你只需编写你想要的所有代码,就像普通的编辑器一样;然后你按下运行 Ctrl+R(实际上是 Cmd+R,因为我使用的是 Mac),它会立即运行所有内容。如果您想更改某些内容(例如,如果有错误),那也很简单——只需更改它并再次按 Ctrl+R。

python 有类似的东西吗?或者您对实现类似行为的方法有什么建议吗?我可以创建一个新文件,保存它,然后从 shell 中使用 python.py 。但这样的步骤太多而且很麻烦。 Eclipse 可能是一个选择,但它太重量级了。我真的在寻找一些轻量级的东西,当我想测试某些东西时我可以旋转它,然后尽快摆脱它。

我有兴趣听到任何想法/建议!

谢谢

I often use ipython (or the regular python shell) to test python code snippets while coding, and it's been very useful. One shortcoming of this, though, is that if I want to test a multi-line segment of code, or want to write multiple lines of code before running, it isn't very convenient to have to do it "line by line". And even going back to change some of the lines is cumbersome because you have to re-type all the code that comes after it.

I'm playing with Groovy right now and I find that it has an excellent solution to this problem: the Groovy Console. You just write all the code you want, it's just like a regular editor; and then you hit run Ctrl+R (Cmd+R actually since I'm on a Mac) and it runs everything at once. If you want to change something (e.g. if there are errors), then that's easy too -- just change it and Ctrl+R again.

Is there an equivalent of this available for python? Or do you have any recommendations on a way to achieve similar behavior? I could just create a new file, save it, and then python <filename>.py from the shell. But that's just too many steps and would be cumbersome. Eclipse may be an option, but it's too heavyweight. I'm really looking for something lightweight that I can just spin up when I want to test something and then get rid of it just as quickly.

I'd be interested to hear any ideas/suggestions!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白色秋天 2024-10-23 22:46:54

您可以尝试一下DreamPie。据我所知,通过快速阅读您链接到的 groovyConsole 页面,DreamPie 具有类似的输入区域/输出区域划分(他们称之为“代码框”和“历史框”)。默认情况下,您执行的代码会从代码框中清除 - groovyConsole 显然不会这样做 - 但您可以轻松检索它(Ctrl+Up),或将首选项设置更改为“执行后将代码保留在代码框中”。

You might give DreamPie a try. As far as I can tell from a quick read of the groovyConsole page you linked to, DreamPie features a similar input area/output area division (they call it "code box" and "history box"). The code you execute is by default cleared from the code box - which groovyConsole apparently doesn't do - but you can easily retrieve it (Ctrl+Up), or change a preference setting to "Leave code in the code box after execution".

烟花易冷人易散 2024-10-23 22:46:54

您是否尝试过使用标准 Python IDE IDLE ?您必须在 IDLE 中将代码保存为 .py,但之后您可以使用 F5 运行它。

Python 文档链接到IDLE 简介,这可能即使有点过时,也会有帮助。

Have you tried using IDLE, the standard Python IDE? You'd have to save the code as <filename>.py within IDLE, but after that you can run it using F5.

The Python docs link to this intro to IDLE, which may be helpful even if it's a little outdated.

忆沫 2024-10-23 22:46:54

我正在使用 emacs 及其 python 模式。
抄送抄送:评估当前缓冲区
但您也可以评估区域(即选择)、函数等...

您甚至可以使 python 模式使用 ipython (就像我一样)。
请参阅 http://ipython.scipy.org/dist/ipython.el 。效果很好

I am using emacs and its python-mode.
C-c C-c: evals the current buffer
but you can also eval region (ie selection), functions etc ...

You can even make python-mode use ipython (like I do).
See http://ipython.scipy.org/dist/ipython.el . It works nicely

南街九尾狐 2024-10-23 22:46:54

你尝试过 PyCrust 吗?它具有出色的多行编辑、复制/粘贴支持。

PyCrust 可以在 wxPython 文档和演示中找到。

Did you try PyCrust? It has excellent multi-line editing, copy/paste support.

PyCrust can be found in wxPython Docs and Demos.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文