Avoid the terminal process to close, after BBEdit runs a script

bashpythonterminaltext-editor

I use BBEdit to write and test Python scripts, and I usually run the scripts in a terminal process, with the "Run in Terminal" command.
Is there a way to have the terminal process opened by BBEdit stay "active", after the script is completed?
I would like not to have the

[Process completed] 

message and instead to still have an active prompt, either the shell or the the Python environment, with all the variables I have created in the script still existing.
This would be similar to the situation when I launch the script from an existing terminal process, either from the shell:

$ python script_name.py

or from the python interpreter:

>>> script_name.py

In particular, in the last case, when the script exits, I still have the process active in the terminal window.

Best Answer

As I understand, you have a Python script in BBEdit.

Python script

You choose to test the code using the "Run in Terminal" option from the '#!' menu.

Run in Terminal

Now a Terminal window opens, runs the script and exits.

exit code

Now here is the culprit. BBEdit does not only run your script, but also adds an exit. There is no option in BBEdit to remove this exit command. But BBEdit is highly scriptable and there are some workarounds. You can create a BBEdit Script (from the Scripts menu) that runs, but personally I think creating Service is the easiest one (run some AppleScript that opens your script in the Terminal as you would have done manually).

In this treat you have provided a script that actually does what you want.