Table of Contents
To Karin, the love of my life. Words simply cant express all that Im grateful for. I know that sometimes I live in
another world but always know that it would be a cold world without you.
To my children, Karren, Shannon, Kasey, Brian, Courtney, Jaren, Carlen, Kristin, Logan, and Ben and to little
Olivia yet to come (as I write this). For some of you I was there at your birth, some of you I have known
for only a few years, but know that each one of you is a treasure to me.
To Mom and Dad, you are still with me every day. I live to make you proud.
About the Author
Jim Knowlton is a software quality engineer with Automatic Data Processing (ADP), Inc., where he leads quality assurance efforts on ADPs computer telephony integration and network video projects. He has been instrumental in introducing automated testing methodologies to their QA effort. He has more than fifteen years of experience in the software industry, including clients such as Symantec, Novell, Nike, and Zions Bank. He has extensive experience in open-source technologies, including Python, Ruby, PHP, Apache, and MySQL, and has also worked extensively in the areas of systems management and enterprise security. Jim holds a bachelor of arts degree in management and is currently working on a master of software engineering degree at Portland State University.
Credits
Acquisitions Editor
Jenny Watson
Development Editor
Ed Connor
Technical Editor
Jesse Keating
Production Editor
Daniel Scribner
Copy Editor
Expat Editing
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinator, Cover
Lynsey Stanford
Proofreader
Nancy Carrasco
Indexer
Robert Swanson
Acknowledgments
First, Id like to acknowledge Guido Van Rossum for creating such a way cool language as Python.
Id like to thank my agent, Neil Salkind, for nursing my insecurities and answering my novice writer questions.
Id like to thank Jenny Watson, my acquisitions editor at Wiley, for being willing to go to bat for an unpublished writers crazy ideas. Thanks to Ed Connor, my development editor, for his gentle prodding, high standards, and encouragement. Thanks also to Jesse Keating for his help with technical editing, and to Brent Rufener for providing a cover photo.
Finally, but most important, thanks to my family for putting up with my frequent unavailability during the last few months writing is a solitary art, and it will be nice to reacquaint myself with my loved ones.
Introduction
Python: Create-Modify-Reuse is designed for all levels of Python developers interested in a practical, hands-on way of learning Python development. This book is designed to show you how to use Python (in combination with the raw processing power of your computer) to accomplish real-world tasks in a more efficient way. Dont look for an exhaustive description of the Python language you wont find it. The books main purpose is not to thoroughly cover the Python language, but rather to show how you can use Python to create robust, real-world applications.
In this respect, the goal is similar to foreign-language books that identify themselves as conversational, focusing on the vocabulary and concepts that people will need the most. Likewise, I focus specifically on the Python knowledge needed to accomplish practical, specific tasks. Along the way, you will learn to create useful, efficient scripts that are easy to maintain and enhance.
The applications, along with source code, are available for download at www.wrox.com.
Who This Book Is For
This book is for developers with some experience with Python who want to explore how to develop full-blown applications. It is also for developers with experience in other languages who want to learn Python by building robust applications. It is well-suited for developers who like to learn by doing, rather than exploring a language feature by feature. To get the most out of the book, you should understand basic programming principles.
Because this book is project-based, you can approach it in numerous ways. You can, of course, read it from cover to cover. Chapters 2 through 8 each cover a different project, so the chapters are independent of each other. However, because each chapter project is covered individually, there may be some overlap of information. I also sometimes refer to explanations of particular topics covered in previous chapters. This will help to reinforce important concepts.
The end of the book contains two appendixes. The first one is a listing of Python resources you can check out for more information. The second one will help you with installing additional components used in some of the examples.
What This Book Covers
Ive always liked the Saturday morning fix-it shows that demonstrate how to build something, such as a cabinet or a deck. The experts on these shows take seemingly large, complex tasks that appear to be beyond the skill level of the average do-it-yourselfer and break them down into smaller, simple tasks, teaching you valuable skills along the way. Thats basically the intention and approach taken in this book, applied to the construction of software instead of home improvements.
This book starts with a basic overview of the Python language, designed for those familiar with other languages but new to Python. It is followed by several chapters, each of which describes a complete project that can be used as-is or modified and extended to suit your particular purposes. Youll find applications that access databases, take advantage of web technologies, and facilitate network communications, to name a few. In addition, and more important than the technologies you will be introduced to, you will learn how to use Python to solve real challenges. Following these chapters are two chapters that cover accessing operating system resources and debugging and testing, respectively.
Each project chapter contains complete instructions describing how to install and use the application, so you can actually see the program run as you learn how to construct and use it, including how the project was designed and prototyped. This book is intended to be both a reference guide and a learning aid, teaching you how to build solutions with Python and providing reference information on a wide variety of Python programming concepts.
It is hoped that this book will help you have fun with Python and build useful applications, and unlike my experience with building a deck without sore thumbs.
How This Book Is Structured
This book is framed around the code itself. This is because developers are typically looking for how to do something; and, as with many activities, you learn how to do something by watching how others do it and trying it yourself. If you want to know how a for loop works, youll find for loops in my code, but thats not the thrust of the book. Instead, this book shows you how to do things: how to build a content management system, how to build a test management system, how to set up a system for tracking customer follow-up, and so on. Along the way, youll learn how to communicate with a SQL database, how to act as a web server or communicate with one, how to access operating system services, and more.