I like to code my Python scripts with Gedit. I have my "uber geek" alter ego who likes to code in Vim, but I must say that I keep coming back to Gedit every time; I just like it.
Today's quick tip is about running python scripts from Gedit. It's a feature that comes in every Python IDE (or any other IDE); you just hit the corresponding key stroke and your script is running (of course with eventual debugging flags). To enable this feature in Gedit, we're going to use its fantastic "External Tools" which is the feature that makes the power of Gedit.
Basically, the External Tools feature allows the user to extend Gedit functionality by executing custom shell commands/scripts inside Gedit. So, to make Gedit run Python scripts directly using a simple key stroke we'll need to provide Gedit with a shell command that does the work and map its functionality to a specific key stroke. We can access the External Tools Manager window by browsing to it through: Tools > Manage External Tools. Adding the custom shell command is straight forward, click the (+) sign at the bottom left of the window, you'll be prompted to give a name to the new command ("Python run" in my case). In the Edit window type in the following shell script:
#!/bin/sh
python3.2 $f
The precedent shell command will invoke the Python interpreter (version 3.2 in my case, use just 'python' for the default interpreter) to run the current Gedit file ($f) which is of course a Python file.
Today's quick tip is about running python scripts from Gedit. It's a feature that comes in every Python IDE (or any other IDE); you just hit the corresponding key stroke and your script is running (of course with eventual debugging flags). To enable this feature in Gedit, we're going to use its fantastic "External Tools" which is the feature that makes the power of Gedit.
Basically, the External Tools feature allows the user to extend Gedit functionality by executing custom shell commands/scripts inside Gedit. So, to make Gedit run Python scripts directly using a simple key stroke we'll need to provide Gedit with a shell command that does the work and map its functionality to a specific key stroke. We can access the External Tools Manager window by browsing to it through: Tools > Manage External Tools. Adding the custom shell command is straight forward, click the (+) sign at the bottom left of the window, you'll be prompted to give a name to the new command ("Python run" in my case). In the Edit window type in the following shell script:
#!/bin/sh
python3.2 $f
The precedent shell command will invoke the Python interpreter (version 3.2 in my case, use just 'python' for the default interpreter) to run the current Gedit file ($f) which is of course a Python file.
Under the Edit space, there's four option fields that give the user the ability to map the new command to a specific shortcut key (F5 in my case) and to customize it even further with options like saving the current file before executing the command or applying the command to the current line of the current file.
That's it. Now you have a shiny custom Run command for Python scripts.
can you post an example ?
ReplyDeleteCool, you made my day, thx! :-)
ReplyDeleteGlad you liked it Tim :-)
ReplyDeletegreat tip !!! I was exactly looking for this feature of Gedit .Like this we can compile and run other lang and see the output in below pane ....thanks again
ReplyDelete