Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GEdit/Python execution plugin?

I'm just starting out learning python with GEdit plus various plugins as my IDE.

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.

Is there a similar facility/plugin which would enable this sort of behaviour for 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. 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)

... or perhaps there is a better way to do code exploration?

Many thx

Simon

like image 526
Simon Woods Avatar asked Jun 08 '10 05:06

Simon Woods


2 Answers

Yes, you use "external tools plugin"

  • http://live.gnome.org/Gedit/ToolLauncherPlugin

As an example,

  1. Edit > Preferences
  2. Plugins
  3. Tick "External Tools"
  4. Close the Preferences Window

  5. Tools > Manage External Tools

  6. Click the "Add new too" icon in the bottom left
  7. Name it "Execute Highlighted Python Code"
  8. give it a keyboard shortcut
  9. change the input combo box to : "highlighted selection"
  10. change the output to : "Display in Bottom Pane"
  11. In the editor window for the tool, replace everything with :

.

#!/usr/bin/env python
import sys
result = eval(sys.stdin.read())
print expression, "=>", result, type(result)

.

like image 139
airtonix Avatar answered Oct 27 '22 03:10

airtonix


If you wish to see the result of entire .py file, you can put this code in your new created external tool window

#!/usr/bin/env python
import sys
exec(sys.stdin.read())

and change the Input to Current document.

like image 30
feifan.overflow Avatar answered Oct 27 '22 02:10

feifan.overflow