You are here: Home ‣ Dive Into Python 3 ‣

# Table of contents

1. What’s New In “Dive Into Python 3”
2. Installing Python
   1. Python on Windows
   2. Python on Mac OS X
   3. Python on Ubuntu Linux
   4. Python from source
   5. The interactive shell
3. Your first Python program
   1. Diving in
   2. Declaring functions
   3. Writing readable code
      1. Docstrings
      2. Function annotations
      3. Style conventions
   4. Everything is an object
      1. The `import` search path
      2. What’s an object?
   5. Indenting code
   6. Running scripts
   7. Further reading
4. Native Python datatypes
   1. Diving in
   2. Booleans
   3. Numbers
      1. Coercing integers to floats and vice-versa
      2. Common numerical operations
      3. Fractions
      4. Trigonometry
      5. Numbers in a boolean context
   4. Lists
      1. Creating a list
      2. Slicing a list
      3. Adding items to a list
      4. Searching for values in a list
      5. Lists in a boolean context
   5. Dictionaries
      1. Creating a dictionary
      2. Modifying a dictionary
      3. Mixed-value dictionaries
      4. Dictionaries in a boolean context
   6. `None`
      1. `None` in a boolean context
   7. Further reading
5. Strings
   1. Diving in
   2. Unicode
      1. How strings are stored in memory
      2. Converting between different character encodings
      3. Specifying character encoding in `.py` files
   3. Strings in Python 3
   4. Common string operations
   5. Formatting strings
   6. The `string` module
   7. Strings vs. bytes
   8. Further reading
6. Regular expressions
   1. Diving in
   2. Case study: street addresses
   3. Case study: Roman numerals
      1. Checking for thousands
      2. Checking for hundreds
   4. Using the `{n,m}` Syntax
      1. Checking for tens and ones
   5. Verbose regular expressions
   6. Case study: parsing phone numbers
   7. Summary
7. Generators
   1. Diving in
   2. I know, let’s use regular expressions!
   3. A list of functions
   4. A list of patterns
   5. A file of patterns
   6. Generators
      1. A Fibonacci generator
      2. A plural rule generator
8. Iterators
   1. Diving In
   2. Defining Classes
   3. Instantiating Classes
   4. Instance Variables
   5. A Fibonacci iterator
   6. A Plural Rule Iterator
   7. Further Reading
9. Advanced Iterators
   1. Diving In
   2. Finding all occurrences of a pattern
   3. Finding the unique items in a sequence
   4. Making assertions
   5. Generator expressions
   6. Calculating Permutations… The Lazy Way!
   7. Other Fun Stuff in the `itertools` Module
   8. A New Kind Of String Manipulation
   9. Evaluating Arbitrary Strings As Python Expressions
   10. Putting It All Together
   11. Further Reading
10. Unit testing
    1. (Not) diving in
    2. A single question
    3. “Halt and catch fire”
    4. More halting, more fire
    5. ...
11. Test-first programming
    1. ...
12. Refactoring your code
    1. Diving in
    2. Handling changing requirements
    3. Refactoring
    4. Summary
13. Advanced Classes
    1. Diving in
14. Files
    1. File objects
    2. Reading files
    3. Close your files... or don't
    4. Handling errors (exceptions)
    5. Writing to files
15. XML Processing
    1. ...major changes afoot...
    2. lxml 2.2 officially supports Python 3
16. HTML processing
    1. Diving in
    2. html5lib
       1. Installing html5lib
       2. Using html5lib
    3. Extracting data from HTML documents
    4. Building HTML documents
    5. Putting it all together
    6. Summary
17. HTTP web services
    1. Diving in
    2. How not to fetch data over HTTP
    3. Features of HTTP
       1. User-Agent
       2. Redirects
       3. Last-Modified/If-Modified-Since
       4. ETag-If-None-Match
       5. Compression
    4. Differences from Python 2
    5. httplib2 (note: needs port)
       1. Installing httplib2
       2. Why httplib2 is better than http.client
    6. Debugging HTTP web services
    7. Setting the User-Agent
    8. Handling Last-Modified and ETag
    9. Handling redirects
    10. Handling compressed data
    11. Putting it all together
    12. Summary
18. Performance tuning
    1. Diving in
    2. Using the timeit module
    3. Optimizing regular expressions
    4. Optimizing dictionary lookups
    5. Optimizing list operations
    6. Optimizing string manipulation
    7. Summary
19. Packaging Python libraries
    1. A brief history of packaging (and why it's harder than you think)
    2. setuptools
    3. distutils
    4. Eggs
    5. pip
    6. Platform-specific packaging
       1. Packaging by Linux distributions
       2. Py2exe
20. Creating graphics with the Python Imaging Library
    1. ...will likely get ported in time...
21. Where to go from here (tentative because most of these have not been ported to Python 3 yet)
    1. WSGI
    2. Django
    3. Pylons
    4. TurboGears
    5. AppEngine
    6. IronPython
    7. Jython
    8. PyPy
    9. Stackless Python
22. Case study: porting `chardet` to Python 3
    1. Introducing `chardet`: a mini-FAQ
       1. What is character encoding auto-detection?
       2. Isn’t that impossible?
       3. Who wrote this detection algorithm?
       4. Yippie! Screw the standards, I’ll just auto-detect everything!
       5. Why bother with auto-detection if it’s slow, inaccurate, and non-standard?
    2. Diving in
       1. `UTF-n` with a BOM
       2. Escaped encodings
       3. Multi-byte encodings
       4. Single-byte encodings
       5. `windows-1252`
    3. Running `2to3`
    4. Fixing what `2to3` can’t
       1. `False` is invalid syntax
       2. No module named `constants`
       3. Name 'file' is not defined
       4. Can’t use a string pattern on a bytes-like object
       5. Can’t convert '`bytes`' object to `str` implicitly

- Appendix A. Porting code to Python 3 with `2to3`
  1. Diving in
  2. `print` statement
  3. Unicode string literals
  4. `unicode()` global function
  5. `long` data type
  6. <> comparison
  7. `has_key()` dictionary method
  8. Dictionary methods that return lists
  9. Modules that have been renamed or reorganized
     1. `http`
     2. `urllib`
     3. `dbm`
     4. `xmlrpc`
     5. Other modules
  10. Relative imports within a package
  11. `next()` iterator method
  12. `filter()` global function
  13. `map()` global function
  14. `reduce()` global function (3.1+)
  15. `apply()` global function
  16. `intern()` global function
  17. `exec` statement
  18. `execfile` statement (3.1+)
  19. `repr` literals (backticks)
  20. `try...except` statement
  21. `raise` statement
  22. `throw` method on generators
  23. `xrange()` global function
  24. `raw_input()` and `input()` global functions
  25. `func_*` function attributes
  26. `xreadlines()` I/O method
  27. `lambda` functions that take a tuple instead of multiple parameters
  28. Special method attributes
  29. `__nonzero__` special method
  30. Octal literals
  31. `sys.maxint`
  32. `callable()` global function
  33. `zip()` global function
  34. `StandardError()` exception
  35. `types` module constants
  36. `isinstance()` global function (3.1+)
  37. `basestring` datatype
  38. `itertools` module
  39. `sys.exc_type`, `sys.exc_value`, `sys.exc_traceback`
  40. List comprehensions over tuples
  41. `os.getcwdu()` function
  42. Metaclasses
  43. Matters of style
      1. `set()` literals
      2. `buffer()` global function
      3. Whitespace around commas
      4. Common idioms
- Appendix B. Special Method Names
  1. Diving in
  2. Basics
  3. Classes That Act Like Iterators
  4. Computed Attributes
  5. Classes That Act Like Functions
  6. Classes That Act Like Sequences
  7. Classes That Act Like Dictionaries
  8. Classes That Act Like Numbers
  9. Classes That Can Be Compared
  10. Classes That Can Be Serialized
  11. Classes That Can Be Used in a `with` Block
  12. Really Esoteric Stuff

Orphans (not sure where these belong yet):

- Tuples
- List comprehensions
- Set comprehensions
- Dictionary comprehensions
- Views (several dictionary methods return them, they're dynamic, update when the dictionary changes, etc.)
- Decorators
- Importing modules
  1. ...mention why from module import * is only allowed at module level

© 2001–9 Mark Pilgrim