diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index 0cbb231..fd6e061 100644 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -3,8 +3,8 @@ Case study: porting chardet to Python 3 - Dive into Python 3 - + -

Dive Into Python 3 will cover Python 3 and its differences from Python 2. Compared to the original Dive Into Python, it will be about 50% revised and 50% new material. I will publish drafts online as I go. The final version will be published on paper by Apress. The book will remain online under the CC-BY-3.0 license. -

There is a changelog, a feed, and discussion on Reddit. The final version will be downloadable as HTML and PDF. During development, the only way to download it is to clone the Mercurial repository: +

Dive Into Python 3 will cover Python 3 and its differences from Python 2. Compared to the original Dive Into Python, it will be about 50% revised and 50% new material. I will publish drafts online as I go. The final version will be published on paper by Apress. The book will remain online under the CC-BY-3.0 license. +

Here’s what I’ve written so far:

+ + +

There is a changelog, a feed, and discussion on Reddit. During development, you can download the book by cloning the Mercurial repository:

you@localhost:~$ hg clone http://hg.diveintopython3.org/ diveintopython3
-

Below is the draft table of contents. It is not finalized. Only a few chapters have been written so far. The rest is just stubs and random notes to myself. -

Installing Python

-

Python on Windows

-

Python on Mac OS X

-

Python on Linux

-

Python from source

-

The interactive shell

-

Summary

-

Your first Python program

-

Diving in

-

Declaring functions

-

How Python's datatypes compare to other programming languages

-

Writing readable code

-

Why bother?

-

Docstrings

-

Function annotations

-

Style conventions

-

Everything is an object

-

The import search path

-

What's an object?

-

Indenting code

-

Testing modules

-

Summary

-

Native Python datatypes

- -

Lists

-

Differences from Python 2

-

Creating new a list

-

Modifying a list

-

Searching a list

-

Deleting elements from a list

-

List operators

-

Looping through a list (list comprehensions)

-

Tuples

-

Dictionaries

-

Differences from Python 2

-

Creating a new dictionary

-

Modifying a dictionary

-

Deleting items from a dictionary

-

Looping through a dictionary (dictionary comprehensions)

-

Dictionary views

-

Sets

-

Differences from Python 2

-

Creating a new set

-

Modifying a set

-

Deleting elements from a set

-

Common set operations: union, intersection, and difference

-

Frozen sets

-

Numbers

-

Differences from Python 2

-

Integers

-

Long integers

-

Floating point numbers

-

Complex numbers

-

Common numerical operations

-

- -

Iterators

-

Generators

-

Views

-

...

-

Strings

-

There ain't no such thing as "plain text"

-

A brief history of character encoding

-

What's a character?

-

How strings are stored in memory

-

Converting between different character encodings

-

Differences from Python 2

-

Formatting strings

-

What's my string?

-

Lists and strings

-

Historical note on the string module

-

Byte streams

-

Summary

-

The power of introspection

-

Diving in

-

Using optional and named arguments

-

Keyword-only arguments

-

Using type, str, dir, and other built-in functions

-

The type function

-

The str function

-

Built-in functions

-

Getting object references with getattr

-

getattr with modules

-

getattr as a dispatcher

-

Filtering lists

-

The peculiar nature of and and or

-

Using the and-or trick

-

Using lambda functions

-

Real-world lambda functions

-

Putting it all together

-

Summary

-

Objects and object-orientation

-

...major changes afoot...

-

...stuff about decorators...

-

...stuff about importing modules...

-

...mention why "from module import *" is only allowed at module level

-

Exceptions

-

...

-

Files

-

File objects

-

Reading files

-

Close your files... or don't

-

Handling I/O errors

-

Writing to files

-

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

-

HTML processing

-

Diving in

-

html5lib

-

Installing html5lib

-

Using html5lib

-

Extracting data from HTML documents

-

Building HTML documents

-

Putting it all together

-

Summary

-

XML Processing

-

...major changes afoot...

-

HTTP web services

-

Diving in

-

How not to fetch data over HTTP

-

Features of HTTP

-

User-Agent

-

Redirects

-

Last-Modified/If-Modified-Since

-

ETag-If-None-Match

-

Compression

-

Differences from Python 2

-

httplib2 (note: needs port)

-

Installing httplib2

-

Why httplib2 is better than http.client

-

Debugging HTTP web services

-

Setting the User-Agent

-

Handling Last-Modified and ETag

-

Handling redirects

-

Handling compressed data

-

Putting it all together

-

Summary

-

Unit testing

-

Introduction to Roman numerals

-

Diving in

-

Introducing romantest.py

-

Testing for success

-

Testing for failure

-

Testing for sanity

-

Test-first programming

-

roman.py, stage 1

-

roman.py, stage 2

-

roman.py, stage 3

-

roman.py, stage 4

-

roman.py, stage 5

-

Refactoring your code

-

Handling bugs

-

Handling changing requirements

-

The art of refactoring

-

Postscript

-

Summary

-

Dynamic functions

-

Diving in

-

plural.py, stage 1

-

plural.py, stage 2

-

plural.py, stage 3

-

plural.py, stage 4

-

plural.py, stage 5

-

plural.py, stage 6

-

Summary

-

Metaclasses

-

...once I figure out WTF metaclasses are...

-

Performance tuning

-

Diving in

-

Using the timeit module

-

Optimizing regular expressions

-

Optimizing dictionary lookups

-

Optimizing list operations

-

Optimizing string manipulation

-

Summary

-

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

- -

A brief history of packaging (and why it's harder than you think)

-

setuptools

-

distutils

-

Eggs

-

pip

-

Platform-specific packaging

-

Packaging by Linux distributions

-

Py2exe

-

Creating graphics with the Python Imaging Library

-

...will likely get ported in time...

-

Where to go from here

-

Tentative because most of these have not been ported to Python 3 yet. -

WSGI

-

Django

-

Pylons

-

TurboGears

-

AppEngine

-

IronPython

-

Jython

-

PyPy

-

Stackless Python

-

Scripts and streams

-

...will be folded into other chapters...

-

Functional programming

-

...bits and pieces will be folded into other chapters...

-

SOAP web services

-

...no one will miss you...

-
-

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. Exceptions -
  21. try...except statement -
  22. raise statement -
  23. throw method on generators -
  24. xrange() global function -
  25. raw_input() and input() global functions -
  26. func_* function attributes -
  27. xreadlines() I/O method -
  28. lambda functions with multiple parameters -
  29. Special method attributes -
  30. __nonzero__ special class attribute -
  31. Octal literals -
  32. sys.maxint -
  33. callable() global function -
  34. zip() global function -
  35. StandardError() exception -
  36. types module constants -
  37. isinstance() global function (3.1+) -
  38. basestring datatype -
  39. itertools module -
  40. sys.exc_type, sys.exc_value, sys.exc_traceback -
  41. List comprehensions over tuples -
  42. os.getcwdu() function -
  43. Metaclasses -
  44. Matters of style -
      -
    1. set() literals -
    2. buffer() global function -
    3. Whitespace around commas -
    4. Common idioms -
    -
-
+

The final version will be downloadable as HTML and PDF.

This site is optimized for Lynx just because fuck you.
I’m told it also looks good in graphical browsers.

© 2001-4, 2009 ark Pilgrim, CC-BY-3.0 +

© 2001-4, 2009 ark Pilgrim, CC-BY-3.0 + + diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 7fb6626..236c902 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -3,8 +3,8 @@ Porting code to Python 3 with 2to3 - Dive into Python 3 - + + + +

+

Table of contents

+
    +
  1. 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 +
    +
  2. 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 +
    +
  3. Native Python datatypes +
      +
    1. Diving in +
    2. Booleans +
    3. Numbers +
        +
      1. Integers +
      2. Floating point numbers +
      3. Fractions +
      4. Complex numbers +
      5. Common operations on numbers +
      6. The math module +
      +
    4. Lists +
        +
      1. Creating new a list +
      2. Modifying a list +
      3. Searching a list +
      4. Deleting elements from a list +
      5. Common operations on lists +
      +
    5. Sets +
        +
      1. Creating a new set +
      2. Modifying a set +
      3. Deleting elements from a set +
      4. Common operations on sets +
      5. Frozen sets +
      +
    6. Dictionaries +
        +
      1. Creating a new dictionary +
      2. Modifying a dictionary +
      3. Deleting items from a dictionary +
      4. Common operations on dictionaries +
      +
    7. None +
    +
  4. Strings +
      +
    1. There ain't no such thing as "plain text" +
        +
      1. A brief history of character encoding +
      2. What's a character? +
      3. How strings are stored in memory +
      4. Converting between different character encodings +
      +
    2. Formatting strings +
    3. What's my string? +
    4. Lists and strings +
    5. Historical note on the string module +
    6. Byte streams +
    7. Summary +
    +
  5. The power of introspection +
      +
    1. Diving in +
    2. Using optional and named arguments +
        +
      1. Keyword-only arguments +
      +
    3. Using type, str, dir, and other built-in functions +
        +
      1. The type function +
      2. The str function +
      3. Built-in functions +
      +
    4. Getting object references with getattr +
        +
      1. getattr with modules +
      2. getattr as a dispatcher +
      +
    5. Filtering lists +
    6. Using lambda functions +
    7. Putting it all together +
    8. Summary +
    +
  6. Objects and object-orientation +
      +
    1. ...major changes afoot... +
    2. ...stuff about decorators... +
    3. ...stuff about importing modules... +
        +
      1. ...mention why "from module import *" is only allowed at module level +
      +
    +
  7. Exceptions +
      +
    1. ... +
    +
  8. Files +
      +
    1. File objects +
    2. Reading files +
    3. Close your files... or don't +
    4. Handling I/O errors +
    5. Writing to files +
    +
  9. 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 +
    +
  10. 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 +
    +
  11. XML Processing +
      +
    1. ...major changes afoot... +
    +
  12. 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 +
    +
  13. Unit testing +
      +
    1. Introduction to Roman numerals +
    2. Diving in +
    3. Introducing romantest.py +
    4. Testing for success +
    5. Testing for failure +
    6. Testing for sanity +
    +
  14. Test-first programming +
      +
    1. roman.py, stage 1 +
    2. roman.py, stage 2 +
    3. roman.py, stage 3 +
    4. roman.py, stage 4 +
    5. roman.py, stage 5 +
    +
  15. Refactoring your code +
      +
    1. Handling bugs +
    2. Handling changing requirements +
    3. The art of refactoring +
    4. Postscript +
    5. Summary +
    +
  16. Dynamic functions +
      +
    1. Diving in +
    2. plural.py, stage 1 +
    3. plural.py, stage 2 +
    4. plural.py, stage 3 +
    5. plural.py, stage 4 +
    6. plural.py, stage 5 +
    7. plural.py, stage 6 +
    8. Summary +
    +
  17. Metaclasses +
      +
    1. ...once I figure out WTF metaclasses are... +
    +
  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. 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 +
      +
    +
  20. 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 +
      +
    +
  21. Creating graphics with the Python Imaging Library +
      +
    1. ...will likely get ported in time... +
    +
  22. 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 +
    +
+ +

Orphans (not sure where these belong yet): +

+

© 2001-4, 2009 ark Pilgrim, CC-BY-3.0 + + diff --git a/your-first-python-program.html b/your-first-python-program.html index e0359b6..4d3bd2c 100644 --- a/your-first-python-program.html +++ b/your-first-python-program.html @@ -3,8 +3,8 @@ Your first Python program - Dive into Python 3 - +