Run Python script in Shell (IDLE) from BBEdit/TextWrangler

Viewed 6384

I began to learn Python a few hours ago and I was wondering if it's possible to execute a script which I wrote in the BBEdit text editor in the Python Shell just with a click.

There are options to run it in the Mac Terminal and in the Debugger but being able to execute it directly would make learning a lot easier.

The tab used for executing/debugging code in BBEdit

3 Answers

You can run the current script (the script contained in the front window) just using the BBEdit command "Run", from the "#!" menu (this menu is sometimes called "shebang" menu) or by pressing CMD – R.

This command runs the script, and prints the output in a new BBEdit window.

Make sure to add the following code at the very first line of your script:

#!/usr/bin/env python

or in general

#!path/to/python [arguments]

This makes sure that the python interpreter is called, to run your script. Another option is to use the "Run in terminal" command, from the same "#!" menu. In this case, a new terminal window is created, and the output of your script will be sent there.

If you want BBEdit to save the unsaved changes in the script before launching it, make sure to read this other Stack Exchange page: automatic save before “Run in Terminal” in BBEdit

I have been using BBedit since it first came out and have watched it grow over the years. So I have to agree with Fabio with his BBEdit preference comment and using it to run a python script. However, the syntax check does not always catch things, so an error may show up when using the run or run in terminal commands. It seems that BBEdit checks do not different between python 2 and python 3 until it runs.

Related