Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 456
Fabian Stern Avatar asked Jan 29 '23 22:01

Fabian Stern


2 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

like image 143
Fabio Avatar answered Feb 02 '23 09:02

Fabio


I think PyCharm make things more easy for you

like image 29
Filippos Ser Avatar answered Feb 02 '23 10:02

Filippos Ser