Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 for an OS that uses Python 2 internally; we have to distinguish our new Python 3 from the OS's internal python command.

The application prompted us, and we entered a temperature of 8. The output shows that 8°C is about 46°F. We'll need to wear a coat...