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

Script file rules


A Python script file must adhere to only one simple rule: it must be pure text. In some cases, a poorly-chosen filename can lead to problems, so we'll add two recommendations that are often helpful:

  • The content must be pure text; ideally encoded in UTF-8, although ASCII is also popular.

  • The filename should follow the Python identifier rules. It should start with a letter and use only letters, digits, and the _ character. Filenames that begin and end with __ (two underscores) are reserved and have special meanings for Python.

  • The extension should be .py.

The two additional recommendations are essential for writing modules and packages, but are not required to write a simple script.

A script is simply a sequence of statements; it's identical to what we might do at the REPL prompt with only one difference: a script has no implicit printed output. We must use the print() function in a script to see any results. In larger applications, we often use the logging module to produce more...