The Quick Python Book is a clear, concise introduction to Python, one of the most elegant programming languages in existence. This book is designed so that you can use it to quickly become proficient in Python. However, it provides more than just a beginner's tutorial. Even once you've become more experienced, it should continue to be quite valuable to you as an indexed cache of information on the bulk of the Python concepts and constructs of which you will find yourself wanting to refresh or augment your knowledge.
about the authors
about the cover illustration
Part 1 Starting out
1. About Python
1.1. Why should I use it?
1.2. A look at languages
1.3. A comparison of Python and other languages
1.4. What’s the catch?
1.5. Have your language and Python too!
1.6. Python and open source software
2. About this book
2.1. How to use this book
2.2. Learning Python by example
2.3. Formatting conventions for code examples
2.4. What you will find in this book
2.5. Where to find more information
3. Getting started
3.1. Installing Python
3.2. IDLE and the basic interactive mode
3.3. Hello, world
3.4. Using IDLE’s Python Shell window
Part 2 The essentials
4. The Quick Python overview
4.1. About this chapter
4.2. Python synopsis
4.3. Built-in data types
4.4. Control flow structures
4.5. Module creation
4.6. Object-oriented programming
5. The absolute basics
5.1. Indentation and block-structuring
5.3. Variables and assignments
5.7. The None value
5.8. Built-in operators
6. Lists and tuples
6.1. Lists are like arrays
6.2. List indices
6.3. Modifying lists
6.5. Other common list operations
6.6. Nested lists and deep copies
7.1. Strings as sequences of characters
7.2. Basic string operations
7.3. Special characters and escape sequences
7.4. The 'string' module
7.5. Converting from objects to strings
7.6. Formatting strings
8.1. What is a dictionary?
8.2. Other dictionary operations
8.3. Word counting
8.4. What can be used as a key?
8.5. Sparse matrices
8.6. Dictionaries as caches
8.7. Efficiency of dictionaries
9. Control flow
9.1. The while loop
9.2. The if-elif-else statement
9.3. The for loop
9.4. Statements, blocks, and indentation
9.5. Boolean values and expressions
10. Functions and procedures
10.1. Basic function and procedure definitions
10.2. Assigning functions to variables
10.3. Lambda expressions
10.4. Function parameter options
10.5. Mutable objects as arguments
10.6. Local and global variables
11. Modules and scoping rules
11.1. What is a module?
11.2. A first module
11.3. The import statement
11.4. The module search path
11.5. Private names in modules
11.6. Library and third-party modules
11.7. Python scoping rules and namespaces
12. Using the filesystem
12.1. Paths and pathnames
12.2. Getting information about files
12.3. More filesystem operations
12.4. Processing all files in a directory subtree
13. Reading and writing files
13.1. Opening files and file objects
13.2. Closing files
13.3. Opening files in write or other modes
13.4. Functions to read and write text or binary data
13.5. Screen input/output and redirection
13.6. The struct module
13.7. Pickling objects into files
13.8. Shelving objects
14.1. Introduction to exceptions
14.2. Exceptions in Python
15.1. Creating a very basic script
15.2. Making a script directly executable on UNIX
15.3. Script execution options in Windows
15.4. Scripts on Windows versus scripts on UNIX
15.5. Scripts and modules
15.6. Creating executable programs with freeze
16. Classes and object-oriented programming
16.1. Defining classes
16.2. Instance variables
16.4. Class variables
16.5. Class methods
16.7. Inheritance with class and instance variables
16.8. Private variables and private methods
16.9. Scoping rules and namespaces for class instances
16.10. Destructors and memory management
16.11. Multiple inheritance
17. Graphical User Interfaces and Tk
17.1. Installing Tk
17.2. Starting Tk and using Tkinter
17.3. Principles of Tk
17.4. A simple Tkinter application
17.5. Creating widgets
17.6. Widget placement
17.7. What else can Tkinter do?
17.8. Alternatives to Tk and Tkinter
Part 3 Advanced language features
18.1. What is a package?
18.2. A first example
18.3. A concrete example
18.4. The all attribute
18.5. Proper use of packages
19. Data types as objects
19.1. Types are objects, too
19.2. Using types
19.3. The types module
19.4. Types and user-defined classes
20. Special method attributes
20.1. What is a special method attribute?
20.2. Making an object behave like a list
20.3. Sample problem 2
20.4. When to use special method attributes
21. Regular expressions
21.1. What is a regular expression?
21.2. Regular expressions with metacharacters
21.3. Regular expressions and raw strings
21.4. Extracting matched text from strings
21.5. Substituting text with regular expressions
21.6. What else can regular expressions do?
Part 4 Advanced topics and applications
22. Python, Windows, and COM
22.2. How to use Python with COM
22.3. Installation and setup
22.4. Anatomy of a Python COM server
22.5. Creating and using the server from Visual Basic
22.6. Passing data in and out of the server
22.8. Using Excel as a client
22.9. Distributed COM
22.10. Client side COM—automating Office
22.11. Type libraries
22.13. Other goodies
22.14. Sources of information
23. Extending Python with C and C++
23.1. Using this chapter
23.2. Compilation details
23.3. A first example
23.4. Memory management
23.5. Writing extensions in C++
23.6. Where to go from here
24. Integration with the Java Virtual Machine: JPython
24.1. What is JPython?
24.2. Prologue: the false hope for a single language
24.3. JPython, the killer scripting language
24.4. Downloading and installing JPython
24.5. Using Java from JPython
24.6. Using JPython from Java
24.7. Compiling JPython classes
24.8. Using Java and JPython together
25. HTML and Python—the HTMLgen package
25.1. Uses for HTMLgen
25.2. How HTMLgen renders objects
25.3. Document model
25.8. Image maps
25.9. The <A> tag
25.10. Call protocol
25.11. CSS1 support
25.12. CGI and forms
25.13. Auxiliary modules
25.14. The future
26. Using 'Zope'
26.2. Object publishing
26.3. Advanced Zope
27. What else can Python do?
Appendix A: The Quick Python reference
About the book
The Quick Python Book first covers the core features of Python (syntax, control flow, basic data structures, etc.) and provides the knowledge to write basic but useful scripts. Features in Python common to other languages are covered very concisely, while features unique to Python are explained in detail.
It next discusses Python features which would be useful to anyone using Python in larger applications, including facilities for managing large collections of code, object-oriented programming, advanced string handling, etc.
The last section of the book discusses advanced topics: Windows/COM programming with Python, integrating Python and Java (Python is one of the few languages other than Java which can be compiled into Java bytecode), extending the Python language with C, and an introduction to some of the advanced web site building tools that are available for Python.
The new integrated development environment bundled with Python release 1.5.2 (IDLE) is undergoing rapid evolution. Therefore the authors are maintaining an online tutorial in HTML format which will be updated for new releases of IDLE. This can be downloaded from: http://www.python.org/idle/doc/.
In order to assist with the continued development of Python, the authors are donating 24% of the royalties earned by this book to Python Software Activity.
Translation rights for The Quick Python Book have been granted for German and Czechoslovakian editions of this book. If you are interested in learning where to buy this book in a language other than English, please inquire at your local bookseller.
About the reader
The book is aimed at readers who know programming but for whom the Python language is new.
About the authors
Daryl Harms holds a Ph.D. in computer science. He has been working on the design and the development (or the management of the development) of small and large software systems since the mid-1980's. He is currently a software development consultant working out of Calgary, Alberta.
Kenneth McDonald is a longtime programmer/analyst and advocate for free software. He holds the B.Sc. and M.Sc. in computer science and has been, at various times, a Unix system administrator, independent software developer, and investor. His most recent position was with the Washington University School of Medicine, where he worked as part of the Human Genome Project as a programmer/analyst.