Running Python on Your Machine
Downloading Python
- Go to https://www.python.org/downloads/
and download the latest version of Python
- The version number should be greater than 3.5
- This will create a Python directory on your machine
- Inside this directory you will find an application named IDLE
Running IDLE
- When you run IDLE you are talking directly to the Python interpreter
- You will be running Python 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 new window
- You can type Python statements into this window
- But you cannot run the statements
- Notice that you don't see the >>> prompt
- 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 must save this file in order to run it in interactive mode
- You can save this file as a Python script
- Which must have a .py extension
Running a Script in IDLE
- The easiest way to run your script is to select "Run Module" from the Run menu
- When you do this the interactive window moves in front
- And the script is run in this window
- You can run any script from the interactive window if you type
import SCRIPTNAME
- Where SCRIPTNAME is the filename without the .py extension
- The script will run when you hit Enter