This is part 2 in a five part series on getting started with Python on macOS. See part 1.
Installing an editor
While it is possible to do Python stuff just on the command line, it is still very useful to have a text editor that can run code. This is so we can do some proper programming and scripting. Atom is a good, and free, option.
An example script
After installing Atom, we can open it and write our first Python script:
Write the two lines above into an Atom file and save it with the *.py file extension to indicate that it is a python script.
You should also start all of your Python scripts with a shebang line to indicate by which programming language the script should be interpreted when run. The line indicates the path to the Python 3 installation.
Set default editor
Now, navigate to your saved hw.py in Finder. Click on it once to highlight it, and press command+I. Now, we can tell macOS to open any *.py files on our system with Atom by default. Select Atom and click 'Change All'.
Set up Atom for running scripts
Python scripts can be run in terminal by entering:
$ python path/to/script.py
But we also want to be able to run scripts within the editor itself. Therefore, in Atom, we can install the package called script.
On the menu Atom > Packages > Script, we now have a set of options with associated keyboard commands. The most important one is command+I.
At this point, if we were to hit command+I, Atom would run the script with the macOS default Python. But we have installed Python 3, and want our scripts to run in that version. We fix this first going to Atom > Preferences..., then clicking the Open Config Folder button, then navigating to .atom/packages/script/lib/grammars/python.coffee. Next, we edit the python.coffee file so that it says 'python3' instead of 'python' (in two places). This may be overkill, if you already changed the aliases in the end of part 1 of this tutorial.
Finally, close python.coffee, save it, and close and restart Atom.
Now, if we double-click on our hw.py in Finder, it will open in Atom. And, if we hit command+I in Atom, the script will run (in Python 3).