GEdit/Python execution plugin?

Simon Woods picture Simon Woods · Jun 8, 2010 · Viewed 23k times · Source

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

Answer

airtonix picture airtonix · Sep 22, 2010

Yes, you use "external tools plugin"

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)

.