diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index 8a66935..965a80c 100644 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -10,12 +10,14 @@ body{counter-reset:h1 19} +

skip to main content +

Case study: porting chardet to Python 3

Words, words. They’re all we have to go on.
Rosencrantz and Guildenstern are Dead

    -
  1. Introducing chardet: a mini-FAQ +
  2. Introducing chardet
    1. What is character encoding auto-detection?
    2. Isn’t that impossible? @@ -41,7 +43,7 @@ body{counter-reset:h1 19}
    3. Can’t convert 'bytes' object to str implicitly
-

Introducing chardet: a mini-FAQ

+

Introducing chardet: a mini-FAQ

When you think of “text,” you probably think of “characters and symbols I see on my computer screen.” But computers don’t deal in characters and symbols; they deal in bits and bytes. Every piece of text you’ve ever seen on a computer screen is actually stored in a particular character encoding. There are many different character encodings, some optimized for particular languages like Russian or Chinese or English, and others that can be used for multiple languages. Very roughly speaking, the character encoding provides a mapping between the stuff you see on your screen and the stuff your computer actually stores in memory and on disk.

In reality, it’s more complicated than that. Many characters are common to multiple encodings, but each encoding may use a different sequence of bytes to actually store those characters in memory or on disk. So you can think of the character encoding as a kind of decryption key for the text. Whenever someone gives you a sequence of bytes and claims it’s “text”, you need to know what character encoding they used so you can decode the bytes into characters and display them (or process them, or whatever).

What is character encoding auto-detection?

diff --git a/dip3.css b/dip3.css index 9941ef5..52aadce 100644 --- a/dip3.css +++ b/dip3.css @@ -6,7 +6,8 @@ a:link{color:#1b67c9} a:visited{color:darkorchid} h1 a,h2 a,h3 a,#nav a{color:inherit !important} abbr,acronym{letter-spacing:0.1em;text-transform:lowercase;font-variant:small-caps} -h1,h2,h3,p,ul,ol,#nav{margin:1.75em 0} +h1,h2,h3,p,ul,ol,#search{margin:1.75em 0} +#search div{float:right} li ol{margin:0} h1,h2,h3{font-size:medium} h1{background:papayawhip;color:#000;width:100%;margin:0} @@ -30,12 +31,12 @@ span,tr + tr th:first-child{font-family:'Arial Unicode MS',sans-serif;font-style .note{margin-left:4.94em} .note span{display:block;float:left;font-size:xx-large;line-height:0.875em;margin:0 0.22em 0 -1.22em} table.simple th{font-family:inherit !important} +.fr{width:auto;margin-top:4.308em;border:1px dotted} +.fr h4{margin-top:-1.2em;margin-left:-1em;width:8.5em;border:1px dotted;padding: 3px 3px 3px 13px;background:#fff;color:inherit;position:relative} +tr.hover,li.hover{background:#eee;color:inherit;cursor:default} body{counter-reset:h1} h1:before{counter-increment:h1;content:counter(h1) ". "} h1{counter-reset:h2} h2:before{counter-increment:h2;content:counter(h1) "." counter(h2) ". "} h2{counter-reset:h3} h3:before{counter-increment:h3;content:counter(h1) "." counter(h2) "." counter(h3) ". "} -tr.hover,li.hover{background:#eee;color:inherit;cursor:default} -.fr{width:auto;margin-top:4.308em;border:1px dotted} -.fr h4{margin-top:-1.2em;margin-left:-1em;width:8.5em;border:1px dotted;padding: 3px 3px 3px 13px;background:#fff;color:inherit;position:relative} \ No newline at end of file diff --git a/index.html b/index.html index fe29e5e..211729a 100644 --- a/index.html +++ b/index.html @@ -12,8 +12,9 @@ h3{margin-left:3.5em} -

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 book 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. 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 book 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 offer HTML and PDF downloads. During development, the only way to download it is to clone the Mercurial repository:

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

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

@@ -23,7 +24,7 @@ h3{margin-left:3.5em}

Python from source

The interactive shell

Summary

-

Your first Python program

+

Your first Python program

Diving in

Declaring functions

How Python's datatypes compare to other programming languages

diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 583d260..4746a63 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -12,6 +12,8 @@ h3:before{counter-increment:h3;content:"A." counter(h2) "." counter(h3) ". "} +

skip to main content +

Porting code to Python 3 with 2to3

Life is pleasant. Death is peaceful. It’s the transition that’s troublesome.
— Isaac Asimov (attributed) diff --git a/symbols.txt b/symbols.txt index 8a6a180..f900705 100644 --- a/symbols.txt +++ b/symbols.txt @@ -19,3 +19,6 @@ http://www.alanwood.net/unicode/dingbats.html ‽ - interrobang ❝ - heavy double turned left comma quotation mark ornament ❞ - heavy double turned right comma quotation mark ornament + +http://docs.python.org/dev/library/turtle.html +http://svn.python.org/projects/python/trunk/Demo/turtle/ diff --git a/your-first-python-program.html b/your-first-python-program.html index 28e0f16..ca1f472 100644 --- a/your-first-python-program.html +++ b/your-first-python-program.html @@ -10,6 +10,8 @@ body{counter-reset:h1 1} +

skip to main content +

Your first Python program

Don’t bury your burden in saintly silence. You have a problem? Great. Rejoice, dive in, and investigate.
Ven. Henepola Gunararatana @@ -17,7 +19,7 @@ body{counter-reset:h1 1}

  1. Diving in
  2. Declaring functions -
  3. Documenting functions +
  4. Writing readable code

Diving in

You know how other books go on and on about programming fundamentals and finally work up to building something useful? Let's skip all that. Here is a complete, working Python program. It probably makes absolutely no sense to you. Don't worry about that, because you're going to dissect it line by line. But read through it first and see what, if anything, you can make of it. @@ -92,7 +94,10 @@ if __name__ == "__main__": Weakly typedC, Objective-CJavaScript, Perl 5, PHP Strongly typedPascal, JavaPython, Ruby -

Documenting functions

+

Writing readable code

+ +FIXME +

You can document a Python function by giving it a docstring. In this program, the approximate_size function has a docstring:

def approximate_size(size, a_kilobyte_is_1024_bytes=True):
     """Convert a file size to human-readable form.