Python 3 for Absolute Beginners

All you will ever need to start programming Python

Tim Hall and J-P Stacey

Contents at a Glance

Introducing Python
Designing Software
Variables and Data Types
Making Choices
Using Lists
Functions
Working with Text
Executable Files, Organization, and Python on the Web
Classes
Exceptions
Reusing Code with Modules and Packages
Simple Windowed Applications

e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 2.50
 Pages
 314 p
 File Size 
 7,505 KB
 File Type
 PDF format
 ISBN-13
 978-1-4302-1632-2 (pbk)
 978-1-4302-1633-9 (electronic) 
 Copyright©   
 2009 by Tim Hall and J-P Stacey 

About the Author
Tim Hall currently provides front—line support for 64 Studio. He has also written
newbie tutorials for Linux User and Developer magazine in between more
mundane system admin and web authoring jobs.
Tim has released albums and performed as a musician and songwriter, both
solo and in collaboration with other artists. He has been further honored as the
holder of the Bardic chair of Glastonbury between 2005 and 2007. Tim uses
Python as his main programming language, primarily as a means for creative
ends, because it is easy to read and fun to learn.
J-P Stacey has been a senior developer at Torchbox Ltd since 2005, building and maintaining
(among other things) Python, Django, and Drupal applications.
He organizes the Oxford Geek Nights and gets involved in tuition and seminars at Torchbox. In his
spare time he reads and writes fiction and blogs, buys too much music, and tries not to startle Cotswold
lions on his bicycle.

About the Technical Reviewer
Duncan Parkes has been coding in Python, both for work and for fun, for roughly
a decade. He drifted into programming largely by accident after initially taking a
doctorate in Combinatorial Group Theory, a branch of Pure Mathematics. As an
ex-mathematician, he loves the clarity and simplicity of Python and needs a bit of
persuading to code in anything else. After completing a technical review of this
book, he joined Apress as an editor in the Open Source group. He currently splits
his time between editing books and coding for mySociety, a charitable
organization that runs most of the UK's best-known democracy web sites.
Duncan lives in Oxford, England, with his wife, Ruth. When away from his
computer, Duncan enjoys playing the guitar very badly, cycling long distances on a
Brompton folding bicycle, and fiddling with old cars.
His friends and colleagues have been known to run sweepstakes on how far these vehicles can get
without the assistance of a breakdown service.

Table of Contents
■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


Bookscreen
e-books shop

Lead Editor: Matthew Moodie
Technical Reviewer: Duncan Parkes
Additional material: Dr. J. Burton Browning
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank
Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Managers: Beth Christmas and Debra Kelly
Copy Editor: Heather Lang
Compositor: LaurelTech
Indexer: BIM Indexing and e-Services
Artist: April Milne
Previous Post Next Post