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

3

5

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

Eupatrid answered 24/7, 2017 at 14:44 Comment(1)
What do you mean with "execute it directly"? You can execute the script using the menu (the tab) you show in the screenshot picture. Then, you can decide where to have the output displayed: in a new BBEdit window, or in the terminal. Please have a look at my answer, and give BBEdit a second chance.. ;)Melodie
M
9

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

Melodie answered 30/9, 2017 at 3:27 Comment(0)
R
1

I think PyCharm make things more easy for you

Ronda answered 24/7, 2017 at 14:47 Comment(1)
I really like to code with BBEdit, because is lightweight, and still really powerful. It's integration with the terminal makes it very convenient, and still much faster/lighter than a full IDE like PyCharm.Melodie
D
0

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.

Danella answered 25/1, 2020 at 21:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.