Running Python on Your Machine
Topics
Downloading Python
- Go to https://www.python.org/downloads/
and download the latest version of Python ...
- greater than version 3.5
- This will create a Python Directory on your machine
- Inside this directory you will find an application named IDLE
Running IDLE
- If you run IDLE it you will be using the Python interpreter ...
- in interactive mode
- You can enter a Python statement in this window ...
- and then hit Enter to run the statement
Syntax Highlighting
- Notice that different parts of the window text appear in different colors
print
appears in purple
- The "hello" inside the parenthesis appears in green
- The output of the print statement appears in blue
- This is called syntax highlighting ...
- a feature your will find in most text editors used by programmers
- Syntax highlighting can make it easier to find mistakes in your code
Creating a Python Script
- If you click and drag down to to "New File" you will get a window ...
- into which you can type Python statements
- But notice that you don't see the >>> prompt ...
- of the Python interactive mode
- If you hit Enter, it will not run the statement ...
- it will merely move down another line
- This window is a Python text editor
- Notice that you see the same syntax highlighting you see in the interactive mode
- This editor has a number of features which make it easier to write Python scripts
- You can save this file as a Python script ...
- which should have a .py extension
Running a Script in IDLE
- If you go back to the interactive mode window and type
import SCRIPTNAME
- where SCRIPTNAME is the filename of the script ...
- without the .py extension ...
- the script will be run inside the interactive mode window
- You can use this editor to create your Python scripts ...
- and then test them in the interactive mode window