[英]GEdit/Python execution plugin?
I'm just starting out learning python with GEdit plus various plugins as my IDE. 我刚开始使用GEdit和各种插件作为我的IDE学习python。
Visual Studio/F# has a feature which permits the highlighting on a piece of text in the code window which then, on a keypress, gets executed in the F# console. Visual Studio / F#具有一项功能,该功能允许突出显示代码窗口中的一段文本,然后在按键时在F#控制台中执行该文本。
Is there a similar facility/plugin which would enable this sort of behaviour for GEdit/Python? 是否有类似的工具/插件可以启用GEdit / Python的这种行为? I do have various execution type plugins (Run In Python,Better Python Console) but they don't give me this particular behaviour - or at least I'm not sure how to configure them to give me this. 我确实有各种执行类型的插件(在Python中运行,更好的Python控制台),但是它们没有给我这种特殊的行为-至少我不确定如何配置它们以提供这种功能。 I find it useful because in learning python, I have some test code I want to execute particular individual lines or small segments of code (rather then a complete file) to try and understand what they are doing (and the copy/paste can get a bit tiresome) 我发现它很有用,因为在学习python时,我有一些测试代码,我想执行特定的单个行或一小段代码(而不是一个完整的文件),以尝试了解它们在做什么(复制/粘贴可以得到一个有点累)
... or perhaps there is a better way to do code exploration? ...或者也许有更好的方法进行代码探索?
Many thx 多谢
Simon 西蒙
Yes, you use "external tools plugin" 是的,您使用“外部工具插件”
As an example, 举个例子,
Close the Preferences Window 关闭偏好设置窗口
Tools > Manage External Tools 工具>管理外部工具
. 。
#!/usr/bin/env python
import sys
result = eval(sys.stdin.read())
print expression, "=>", result, type(result)
. 。
If you wish to see the result of entire .py
file, you can put this code in your new created external tool window 如果希望查看整个.py
文件的结果,可以将此代码放在新创建的外部工具窗口中
#!/usr/bin/env python
import sys
exec(sys.stdin.read())
and change the Input
to Current document
. 并将Input
更改为 Current document
。
最接近体面的IDE ...安装gedit-developer-plugins(通过突触|| apt-get),不要忘记从gEdit的插件(Edit-> Preferences [tab]插件)启用(所需)。快乐编码
To answer your second question, and hopefully guide you in a direction you'll be happier with, I think you ought to consider trying some different editors. 为了回答您的第二个问题,并希望指导您朝着更幸福的方向发展,我认为您应该考虑尝试一些不同的编辑器。 There are many with more powerful code exploration features than GEdit has. 有许多功能比GEdit具有更强大的代码探索功能。 Check out this post: 看看这个帖子:
I installed iPython console in gedit and do most of my simple scripting in it, but gedit is a very simple editor, so it'll not have some advance feature like an IDE 我在gedit中安装了iPython控制台,并在其中进行了大多数简单的脚本编写,但是gedit是一个非常简单的编辑器,因此它没有像IDE这样的高级功能
But if you want code exploring, or auto completion, I recommend a real IDE like Eclipse. 但是,如果您想要代码探索或自动完成,我建议您使用像Eclipse这样的真正IDE。
If you just want a editor, KomodoEdit is fine. 如果您只需要编辑器,可以使用KomodoEdit。
What I do is keep a file called python_temp.py. 我要做的是保留一个名为python_temp.py的文件。 I have a shortcut to it in my dock. 我在码头上有一条捷径。 I use it as a scratch pad. 我用它作为便签本。 Whenever I want to quickly run some code, I copy the code, click the shortcut in the doc, paste in the text and hit f5 to run. 每当我想快速运行一些代码时,我都会复制代码,单击文档中的快捷方式,粘贴文本并按f5键运行。 Quick, easy, simple, flexible. 快速,简便,简单,灵活。
I think what you're looking for is http://live.gnome.org/Gedit/Plugins/BetterPythonConsole . 我认为您正在寻找的是http://live.gnome.org/Gedit/Plugins/BetterPythonConsole 。
You hit F5 and it runs the code in your file in a IDLE-like console. 您按F5键,它将在类似IDLE的控制台中运行文件中的代码。 I don't know if it can only run selected code. 我不知道它是否只能运行选定的代码。 (I don't think it can) but you can always copy the needed code in a new window and run it from there. (我不认为可以),但是您始终可以在新窗口中复制所需的代码,然后从那里运行它。
Have a look through the plugin list for other interesting stuff: http://live.gnome.org/Gedit/Plugins 浏览插件列表中的其他有趣内容: http : //live.gnome.org/Gedit/Plugins
For python, You can use "external tools plugin": 对于python,您可以使用“外部工具插件”:
#!/bin/sh
python3 "$GEDIT_CURRENT_DOCUMENT_PATH"
Option of external tool: Save: Current Document Input: Current Document Output: Display in bottom panel 外部工具选项:保存:当前文档输入:当前文档输出:在底部面板中显示
Language: Python or Python3 语言:Python或Python3
Don't forget the quotes around $GEDIT_CURRENT_DOCUMENT_PATH.... 不要忘记$ GEDIT_CURRENT_DOCUMENT_PATH周围的引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.