■About the Author ........................................................................................................ xi
■About the Technical Reviewer................................................................................... xii
■Chapter 1: Introducing Python ....................................................................................1
Running Python on Various Systems .................................................................................1
Learning While Having Fun ................................................................................................4
Introducing the Interactive Shell........................................................................................4
Choosing to Code with a Text Editor..................................................................................5
Choosing to Code with an Integrated Development Environment......................................5
Getting Started with Programming ....................................................................................5
Creating Your Own Help Files ............................................................................................6
Jargon Busting...................................................................................................................6
Summary ...........................................................................................................................7
■Chapter 2: Designing Software....................................................................................9
Designing Your Own Software (Why Bother?)....................................................................9
Identifying the Problem....................................................................................................10
Creating Your Wish List....................................................................................................12
Devising a Solution ..........................................................................................................13
Breaking Down the Solution into Steps ...........................................................................15
Jargon Busting.................................................................................................................24
Summary .........................................................................................................................25
■Chapter 3: Variables and Data Types.........................................................................27
Choosing Good Identifiers................................................................................................27
Creating Variables and Assigning Values.........................................................................28
Recognizing Different Types of Variables ........................................................................29
Jargon Busting.................................................................................................................45
Summary .........................................................................................................................47
■Chapter 4: Making Choices........................................................................................49
Comparing Things............................................................................................................49
Taking Control of the Process..........................................................................................55
Dealing with Logical Errors..............................................................................................57
Using Conditional Code in the Application .......................................................................61
Now Repeat That .............................................................................................................65
Jargon Busting.................................................................................................................73
Summary .........................................................................................................................74
■Chapter 5: Using Lists................................................................................................75
Working with Python Data Structures..............................................................................75
Tuples ..............................................................................................................................79
Lists .................................................................................................................................80
Sets..................................................................................................................................85
Dictionaries......................................................................................................................86
A Simple Role-Playing Combat Game ..............................................................................89
Jargon Busting.................................................................................................................99
Summary .......................................................................................................................100
■Chapter 6: Functions ...............................................................................................101
Accessing Privileged Information ..................................................................................101
Working with Variable Scope.........................................................................................105
Refactoring rpcombat.py to Reduce Repetition .............................................................108
Jargon Busting...............................................................................................................123
Summary .......................................................................................................................124
■Chapter 7: Working with Text..................................................................................125
Strings and Things.........................................................................................................125
Matching Patterns Using Regular Expressions ..............................................................135
Using Files .....................................................................................................................141
Applications ...................................................................................................................145
Jargon Busting...............................................................................................................159
Summary .......................................................................................................................160
■Chapter 8: Executable Files, Organization, and Python on the Web........................161
Making Programs Executable as Stand-Alone Applications ..........................................161
Organizing Your Project .................................................................................................164
Writing Stylish Code.......................................................................................................165
Importing Modules.........................................................................................................170
Using exec() and eval()...................................................................................................172
Putting Python on the Web ............................................................................................173
Jargon Busting...............................................................................................................179
Summary .......................................................................................................................179
■Chapter 9: Classes...................................................................................................181
Empowering objects ......................................................................................................182
When Should Classes Be Used? ....................................................................................185
Customizing Classes......................................................................................................191
Application .....................................................................................................................200
Jargon Busting...............................................................................................................219
Summary .......................................................................................................................220
■Chapter 10: Exceptions............................................................................................221
When Something Goes Wrong .......................................................................................221
Classes of Exceptions ....................................................................................................224
A Final Note on Pythonic Exception Handling ................................................................238
Jargon Busting...............................................................................................................239
Summary .......................................................................................................................240
■Chapter 11: Reusing Code with Modules and Packages .........................................241
Understanding Python Modules.....................................................................................241
Everyday Module Usage.................................................................................................244
Advanced Module Behavior ...........................................................................................249
Combining Modules into Packages................................................................................252
The Universe of Python packages..................................................................................254
Jargon Busting...............................................................................................................259
Summary .......................................................................................................................260
■Chapter 12: Simple Windowed Applications............................................................261
Using Tkinter..................................................................................................................261
Saying “Hello” with PyGTK ............................................................................................265
Using Glade and tepache to Build Interfaces.................................................................279
Jargon Busting...............................................................................................................282
Summary .......................................................................................................................282
■Index........................................................................................................................283