English 中文(简体)
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

最佳回答

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. Check out this post:

What IDE to use for Python?

问题回答

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)

.

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.

For python, You can use "external tools plugin":

#!/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

Don t forget the quotes around $GEDIT_CURRENT_DOCUMENT_PATH....

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

But if you want code exploring, or auto completion, I recommend a real IDE like Eclipse.

If you just want a editor, KomodoEdit is fine.

What I do is keep a file called 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. Quick, easy, simple, flexible.

I think what you re looking for is http://live.gnome.org/Gedit/Plugins/BetterPythonConsole.

You hit F5 and it runs the code in your file in a IDLE-like console. 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

The closest to a decent IDE... Install gedit-developer-plugins (through synaptic || apt-get) and don t forget to enable (what you need) from gEdit s plugins (Edit->Preferences [tab] plugins) and happy coding





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签