Running a script by the filename

The most common way to run a script is to provide the filename to the Python command. Let's assume we have a file with the unpleasant name of ch12_script1.py in a directory named Chapter_12.

In Linux and Mac OS X, the full name will be Chapter_12/ch12_script1.py. In Windows, the full filename will be Chapter_12\ch12_script1.py. We'll stick with the Linux standard filenames for the remaining examples.

Here's how we can run a script by giving the filename:

MacBookPro-SLott:Code slott$ python3 Chapter_12/ch12_script1.py
Temperature °C: 8
C=8°, F=46°

This output shows the OS prompt. The python3 command that we entered is highlighted. The prompts and the outputs from the script are also shown. This example is typical ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.