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

Creating a hybrid library/application module


A script may import modules, perhaps define some functions or classes, but it will always do the relevant processing. Our first example script had just three lines of relevant processing: two assignment statements, and a function statement that printed a result. This shows the Pythonic ideal of having programs without any boilerplate; we try to avoid syntax that's just overhead.

A possible downside of a perfectly clean approach to scripting is that it's difficult to create unit tests. Each unit test would have to invoke the script as a subprocess; something that can involve quite a bit of OS overhead. The goal of unit testing is to isolate each unit—each function, class, module, package, or script—so that it can be tested separately. Having the OS launch the script file doesn't seem to be properly isolated.

Also, as an application matures, a good script may become a component in a larger, and more comprehensive, application. It can become difficult...