You are here: Home ‣ Dive Into Python 3 ‣
Table of Contents
- What’s New In “Dive Into Python 3”
- Installing Python
- Diving In
- Which Python Is Right For You?
- Installing on Microsoft Windows
- Installing on Mac OS X
- Installing on Ubuntu Linux
- Installing on Other Platforms
- Using The Python Shell
- Python Editors and IDEs
- Your first Python program
- Diving in
- Declaring functions
- Writing readable code
- Docstrings
- The
import search path
- Everything is an object
- What’s an object?
- Indenting code
- Exceptions
- Running scripts
- Further reading
- Native Python datatypes
- Diving in
- Booleans
- Numbers
- Coercing integers to floats and vice-versa
- Common numerical operations
- Fractions
- Trigonometry
- Numbers in a boolean context
- Lists
- Creating a list
- Slicing a list
- Adding items to a list
- Searching for values in a list
- Lists in a boolean context
- Tuples
- Assigning Multiple Values At Once
- Sets
- Creating A Set
- Modifying A Set
- Removing Items From A Set
- Common Set Operations
- Sets In A Boolean Context
- Dictionaries
- Creating a dictionary
- Modifying a dictionary
- Mixed-value dictionaries
- Dictionaries in a boolean context
None
None in a boolean context
- Further reading
- Comprehensions
- Diving In
- Working With Files And Directories
- The Current Working Directory
- Working With Filenames and Directory Names
- Listing Directories
- Getting File Metadata
- Constructing Absolute Pathnames
- List Comprehensions
- Dictionary Comprehensions
- Other Fun Stuff To Do With Dictionary Comprehensions
- Set Comprehensions
- Further Reading
- Strings
- Some Boring Stuff You Need To Understand Before You Can Dive In
- Unicode
- Diving In
- Formatting Strings
- Compound Field Names
- Format Specifiers
- Other Common String Methods
- Slicing A String
- Strings vs. Bytes
- Postscript: Character Encoding Of Python Source Code
- Further Reading
- Regular expressions
- Diving in
- Case study: street addresses
- Case study: Roman numerals
- Checking for thousands
- Checking for hundreds
- Using the
{n,m} Syntax
- Checking for tens and ones
- Verbose regular expressions
- Case study: parsing phone numbers
- Summary
- Closures & Generators
- Diving in
- I know, let’s use regular expressions!
- A list of functions
- A list of patterns
- A file of patterns
- Generators
- A Fibonacci generator
- A plural rule generator
- Classes & Iterators
- Diving In
- Defining Classes
- Instantiating Classes
- Instance Variables
- A Fibonacci iterator
- A Plural Rule Iterator
- Further Reading
- Advanced Iterators
- Diving In
- Finding all occurrences of a pattern
- Finding the unique items in a sequence
- Making assertions
- Generator expressions
- Calculating Permutations… The Lazy Way!
- Other Fun Stuff in the
itertools Module
- A New Kind Of String Manipulation
- Evaluating Arbitrary Strings As Python Expressions
- Putting It All Together
- Further Reading
- Unit Testing
- (Not) Diving In
- A single Question
- “Halt and Catch Fire”
- More Halting, More Fire
- And One More Thing…
- A Pleasing Symmetry
- More Bad Input
- Refactoring
- Diving in
- Handling Changing Requirements
- Refactoring
- Summary
- Files
- Diving In
- Reading From Text Files
- Character Encoding Rears Its Ugly Head
- File Objects
- Reading Data From A Text File
- Closing Files
- Closing Files Automatically
- Reading Data One Line At A Time
- Writing to Text Files
- Character Encoding Again
- Binary Files
- File-like Objects
- Handling Compressed Files
- Standard Input, Output, and Error
- Redirecting Standard Output
- Further Reading
- XML
- Diving In
- A 5-Minute Crash Course in XML
- The Structure Of An Atom Feed
- Parsing XML
- Elements Are Lists
- Attributes Are Dictonaries
- Searching For Nodes Within An XML Document
- Going Further With lxml
- Customizing Your XML Parser
- Incremental Parsing
- Generating XML
- Further Reading
- Serializing Python Objects
- ...diving in...
- HTTP Web Services
- Diving In
- Features of HTTP
- Caching
- Last-Modified Checking
- ETags
- Compression
- Redirects
- How Not To Fetch Data Over HTTP
- What’s On The Wire?
- Introducing
httplib2
- How
httplib2 Handles Caching
- How
httplib2 Handles Last-Modified and ETag Headers
- How
http2lib Handles Compression
- How
httplib2 Handles Redirects
- Beyond HTTP GET
- Beyond HTTP POST
- Further Reading
- Threading & Multiprocessing
- ...
- Case study: porting
chardet to Python 3
- Introducing
chardet: a mini-FAQ
- What is character encoding auto-detection?
- Isn’t that impossible?
- Who wrote this detection algorithm?
- Yippie! Screw the standards, I’ll just auto-detect everything!
- Why bother with auto-detection if it’s slow, inaccurate, and non-standard?
- Diving in
UTF-n with a BOM
- Escaped encodings
- Multi-byte encodings
- Single-byte encodings
windows-1252
- Running
2to3
- Fixing what
2to3 can’t
False is invalid syntax
- No module named
constants
- Name 'file' is not defined
- Can’t use a string pattern on a bytes-like object
- Can’t convert '
bytes' object to str implicitly
- Packaging Python libraries
- ...
- Where to go from here
- Things to read
- Where to look for Python 3-compatible code
© 2001–9 Mark Pilgrim