Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

Click here to view code image


pi@raspberrypi ~ $ python3 py3prog/sample.py
Here is a sample python script.
Here is the second line of the sample script.
pi@raspberrypi ~ $

By the Way: Script Storage Location
It is a good idea to store your Python scripts in a standard location. This book uses the
subdirectory /home/pi/py3prog.

Running a Python Script in IDLE


To run the sample.py script in IDLE, start IDLE and in the main interactive mode window, either
press the key combination Ctrl+O or select the File menu and then Open. The Open window appears.
Navigate to the location of the Python script. In this case, sample.py is located in
/home/pi/py3prog, as shown in Figure 3.8. Click the script to select it and then click the Open
button.


FIGURE 3.8 Opening a Python script in IDLE.

When you click the Open button, another IDLE window opens, showing the Python script and its
directory location and name in the window’s title bar (see Figure 3.9).

Free download pdf