Table of contents - Dive Into Python 3
 

You are here: Home Dive Into Python 3

Table of Contents

  1. What’s New in “Dive Into Python 3”
    1. a.k.a. “the minus level”
  2. Installing Python
    1. Diving In
    2. Which Python Is Right For You?
    3. Installing on Microsoft Windows
    4. Installing on Mac OS X
    5. Installing on Ubuntu Linux
    6. Installing on Other Platforms
    7. Using The Python Shell
    8. Python Editors and IDEs
  3. Your First Python Program
    1. Diving In
    2. Declaring Functions
      1. Optional and Named Arguments
    3. Writing Readable Code
      1. Documentation Strings
    4. The import Search Path
    5. Everything Is An Object
      1. What’s An Object?
    6. Indenting Code
    7. Exceptions
      1. Catching Import Errors
    8. Unbound Variables
    9. Everything is Case-Sensitive
    10. Running Scripts
    11. Further Reading
  4. Native 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. Removing Items From A List
      6. Removing Items From A List: Bonus Round
      7. Lists In A Boolean Context
    5. Tuples
      1. Tuples In A Boolean Context
      2. Assigning Multiple Values At Once
    6. Sets
      1. Creating A Set
      2. Modifying A Set
      3. Removing Items From A Set
      4. Common Set Operations
      5. Sets In A Boolean Context
    7. Dictionaries
      1. Creating A Dictionary
      2. Modifying A Dictionary
      3. Mixed-Value Dictionaries
      4. Dictionaries In A Boolean Context
    8. None
      1. None In A Boolean Context
    9. Further Reading
  5. Comprehensions
    1. Diving In
    2. Working With Files And Directories
      1. The Current Working Directory
      2. Working With Filenames and Directory Names
      3. Listing Directories
      4. Getting File Metadata
      5. Constructing Absolute Pathnames
    3. List Comprehensions
    4. Dictionary Comprehensions
      1. Other Fun Stuff To Do With Dictionary Comprehensions
    5. Set Comprehensions
    6. Further Reading
  6. Strings
    1. Some Boring Stuff You Need To Understand Before You Can Dive In
    2. Unicode
    3. Diving In
    4. Formatting Strings
      1. Compound Field Names
      2. Format Specifiers
    5. Other Common String Methods
      1. Slicing A String
    6. Strings vs. Bytes
    7. Postscript: Character Encoding Of Python Source Code
    8. Further Reading
  7. 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
  8. Closures & 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
    7. Further Reading
  9. Classes & Iterators
    1. Diving In
    2. Defining Classes
      1. The __init__() Method
    3. Instantiating Classes
    4. Instance Variables
    5. A Fibonacci Iterator
    6. A Plural Rule Iterator
    7. Further Reading
  10. 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
  11. Unit Testing
    1. (Not) Diving In
    2. A Single Question
    3. “Halt And Catch Fire”
    4. More Halting, More Fire
    5. And One More Thing…
    6. A Pleasing Symmetry
    7. More Bad Input
  12. Refactoring
    1. Diving In
    2. Handling Changing Requirements
    3. Refactoring
    4. Summary
  13. Files
    1. Diving In
    2. Reading From Text Files
      1. Character Encoding Rears Its Ugly Head
      2. Stream Objects
      3. Reading Data From A Text File
      4. Closing Files
      5. Closing Files Automatically
      6. Reading Data One Line At A Time
    3. Writing to Text Files
      1. Character Encoding Again
    4. Binary Files
    5. Stream Objects From Non-File Sources
      1. Handling Compressed Files
    6. Standard Input, Output, and Error
      1. Redirecting Standard Output
    7. Further Reading
  14. XML
    1. Diving In
    2. A 5-Minute Crash Course in XML
    3. The Structure Of An Atom Feed
    4. Parsing XML
      1. Elements Are Lists
      2. Attributes Are Dictonaries
    5. Searching For Nodes Within An XML Document
    6. Going Further With lxml
    7. Generating XML
    8. Parsing Broken XML
    9. Further Reading
  15. Serializing Python Objects
    1. Diving In
      1. A Quick Note About The Examples in This Chapter
    2. Saving Data to a Pickle File
    3. Loading Data from a Pickle File
    4. Pickling Without a File
    5. Bytes and Strings Rear Their Ugly Heads Again
    6. Debugging Pickle Files
    7. Serializing Python Objects to be Read by Other Languages
    8. Saving Data to a JSON File
    9. Mapping of Python Datatypes to JSON
    10. Serializing Datatypes Unsupported by JSON
    11. Loading Data from a JSON File
    12. Further Reading
  16. HTTP Web Services
    1. Diving In
    2. Features of HTTP
      1. Caching
      2. Last-Modified Checking
      3. ETag Checking
      4. Compression
      5. Redirects
    3. How Not To Fetch Data Over HTTP
    4. What’s On The Wire?
    5. Introducing httplib2
      1. A Short Digression To Explain Why httplib2 Returns Bytes Instead of Strings
      2. How httplib2 Handles Caching
      3. How httplib2 Handles Last-Modified and ETag Headers
      4. How http2lib Handles Compression
      5. How httplib2 Handles Redirects
    6. Beyond HTTP GET
    7. Beyond HTTP POST
    8. Further Reading
  17. Case Study: Porting chardet to Python 3
    1. Diving In
    2. What is Character Encoding Auto-Detection?
      1. Isn’t That Impossible?
      2. Does Such An Algorithm Exist?
    3. Introducing The chardet Module
      1. UTF-n With A BOM
      2. Escaped Encodings
      3. Multi-Byte Encodings
      4. Single-Byte Encodings
      5. windows-1252
    4. Running 2to3
    5. A Short Digression Into Multi-File Modules
    6. 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
      6. Unsupported operand type(s) for +: 'int' and 'bytes'
      7. ord() expected string of length 1, but int found
      8. Unorderable types: int() >= str()
      9. Global name 'reduce' is not defined
    7. Summary
  18. Packaging Python Libraries
    1. Diving In
    2. Things Distutils Can’t Do For You
    3. Directory Structure
    4. Writing Your Setup Script
    5. Classifying Your Package
      1. Examples of Good Package Classifiers
    6. Specifying Additional Files With A Manifest
    7. Checking Your Setup Script for Errors
    8. Creating a Source Distribution
    9. Creating a Graphical Installer
      1. Building Installable Packages for Other Operating Systems
    10. Adding Your Software to The Python Package Index
    11. The Many Possible Futures of Python Packaging
    12. Further Reading
  19. 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
    15. apply() global function
    16. intern() global function
    17. exec statement
    18. execfile statement
    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
    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 (explicit)
      2. buffer() global function (explicit)
      3. Whitespace around commas (explicit)
      4. Common idioms (explicit)
  20. 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 Sets
    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
    13. Further Reading
  21. Where to Go From Here
    1. Things to Read
    2. Where To Look For Python 3-Compatible Code
  22. Troubleshooting
    1. Diving In
    2. Getting to the Command Line
    3. Running Python on the command line

© 2001–11 Mark Pilgrim