search box and more skip links

This commit is contained in:
Mark Pilgrim
2009-02-04 01:22:01 -05:00
parent ae6b88465b
commit 8441b2f82c
6 changed files with 25 additions and 11 deletions
+4 -2
View File
@@ -10,12 +10,14 @@ body{counter-reset:h1 19}
</style>
</head>
<body>
<p class="skip"><a href="#divingin">skip to main content</a>
<form action="http://www.google.com/cse" id="search"><div><input type="hidden" name="cx" value="014021643941856155761:l5eihuescdw"><input type="hidden" name="ie" value="UTF-8">&nbsp;<input name="q" size="31">&nbsp;<input type="submit" name="sa" value="Search"></div><p>You are here: <a href="index.html">Dive Into Python 3</a> <span>&#8227;</span> <b>Chapter 20</b></form>
<h1>Case study: porting <code class="filename">chardet</code> to Python 3</h1>
<blockquote class="q">
<p><span>&#x275D;</span> Words, words. They&#8217;re all we have to go on. <span>&#x275E;</span><br>&mdash; <cite>Rosencrantz and Guildenstern are Dead</cite>
</blockquote>
<ol>
<li><a href="#faq">Introducing <code class="filename">chardet</code>: a mini-FAQ</a>
<li><a href="#divingin">Introducing <code class="filename">chardet</code></a>
<ol>
<li><a href="#faq.what">What is character encoding auto-detection?</a>
<li><a href="#faq.impossible">Isn&#8217;t that impossible?</a>
@@ -41,7 +43,7 @@ body{counter-reset:h1 19}
<li><a href="#cantconvertbytesobject">Can&#8217;t convert '<code>bytes</code>' object to <code>str</code> implicitly</a>
</ol>
</ol>
<h2 id="faq">Introducing <code class="filename">chardet</code>: a mini-FAQ</h2>
<h2 id="divingin">Introducing <code class="filename">chardet</code>: a mini-FAQ</h2>
<p class="fancy">When you think of &#8220;text,&#8221; you probably think of &#8220;characters and symbols I see on my computer screen.&#8221; But computers don&#8217;t deal in characters and symbols; they deal in bits and bytes. Every piece of text you&#8217;ve ever seen on a computer screen is actually stored in a particular <em>character encoding</em>. 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.
<p>In reality, it&#8217;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&#8217;s &#8220;text&#8221;, 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).
<h3 id="faq.what">What is character encoding auto-detection?</h3>
+5 -4
View File
@@ -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}
+4 -3
View File
@@ -12,8 +12,9 @@ h3{margin-left:3.5em}
</style>
</head>
<body>
<p><cite>Dive Into Python 3</cite> will cover Python 3 and its differences from Python 2. Compared to the original <cite><a href="http://diveintopython.org/">Dive Into Python</a></cite>, 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 <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">CC-BY-3.0</a> license.
<p>There is a <a href="http://hg.diveintopython3.org/">changelog</a>, a <a rel="alternate" type="application/atom+xml" href="http://hg.diveintopython3.org/atom-log">feed</a>, and <a href="http://www.reddit.com/search?q=%22Dive+Into+Python+3%22">discussion on Reddit</a>. During development, the only way to download it is to clone the Mercurial repository:
<form action="http://www.google.com/cse" id="search"><div><input type="hidden" name="cx" value="014021643941856155761:l5eihuescdw"><input type="hidden" name="ie" value="UTF-8"><input name="q" size="31">&nbsp;<input type="submit" name="sa" value="Search"></div></form>
<p style="clear:both;margin-top:0;padding-top:1.75em"><cite>Dive Into Python 3</cite> will cover Python 3 and its differences from Python 2. Compared to the original <cite><a href="http://diveintopython.org/">Dive Into Python</a></cite>, 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 <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">CC-BY-3.0</a> license.
<p>There is a <a href="http://hg.diveintopython3.org/">changelog</a>, a <a rel="alternate" type="application/atom+xml" href="http://hg.diveintopython3.org/atom-log">feed</a>, and <a href="http://www.reddit.com/search?q=%22Dive+Into+Python+3%22">discussion on Reddit</a>. The final version will offer HTML and PDF downloads. During development, the only way to download it is to clone the Mercurial repository:
<pre><samp class="prompt">you@localhost:~$ </samp><kbd>hg clone http://hg.diveintopython3.org/ dip3</kbd></pre>
<p>Below is the draft table of contents. It is <b>not finalized</b>. Only a few chapters have been written so far. The rest is just stubs and random notes to myself.
<h1>Installing Python</h1>
@@ -23,7 +24,7 @@ h3{margin-left:3.5em}
<h2>Python from source</h2>
<h2>The interactive shell</h2>
<h2>Summary</h2>
<h1>Your first Python program</h1>
<h1><a href="your-first-python-program.html">Your first Python program</a></h1>
<h2>Diving in</h2>
<h2>Declaring functions</h2>
<h3>How Python's datatypes compare to other programming languages</h3>
+2
View File
@@ -12,6 +12,8 @@ h3:before{counter-increment:h3;content:"A." counter(h2) "." counter(h3) ". "}
</style>
</head>
<body>
<p class="skip"><a href="#divingin">skip to main content</a>
<form action="http://www.google.com/cse" id="search"><div><input type="hidden" name="cx" value="014021643941856155761:l5eihuescdw"><input type="hidden" name="ie" value="UTF-8">&nbsp;<input name="q" size="31">&nbsp;<input type="submit" name="sa" value="Search"></div><p>You are here: <a href="index.html">Dive Into Python 3</a> <span>&#8227;</span> <b>Appendix A</b></form>
<h1>Porting code to Python 3 with <code>2to3</code></h1>
<blockquote class="q">
<p><span>&#x275D;</span> Life is pleasant. Death is peaceful. It&#8217;s the transition that&#8217;s troublesome. <span>&#x275E;</span><br>&mdash; Isaac Asimov (attributed)
+3
View File
@@ -19,3 +19,6 @@ http://www.alanwood.net/unicode/dingbats.html
&#x203D; - interrobang
&#x275D; - heavy double turned left comma quotation mark ornament
&#x275E; - 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/
+7 -2
View File
@@ -10,6 +10,8 @@ body{counter-reset:h1 1}
</style>
</head>
<body>
<p class="skip"><a href="#divingin">skip to main content</a>
<form action="http://www.google.com/cse" id="search"><div><input type="hidden" name="cx" value="014021643941856155761:l5eihuescdw"><input type="hidden" name="ie" value="UTF-8">&nbsp;<input name="q" size="31">&nbsp;<input type="submit" name="sa" value="Search"></div><p>You are here: <a href="index.html">Dive Into Python 3</a> <span>&#8227;</span> <b>Chapter 2</b></form>
<h1>Your first Python program</h1>
<blockquote class="q">
<p><span>&#x275D;</span> Don&#8217;t bury your burden in saintly silence. You have a problem? Great. Rejoice, dive in, and investigate. <span>&#x275E;</span><br>&mdash; <cite>Ven. Henepola Gunararatana</cite>
@@ -17,7 +19,7 @@ body{counter-reset:h1 1}
<ol>
<li><a href="#divingin">Diving in</a>
<li><a href="#declaringfunctions">Declaring functions</a>
<li><a href="#documentingfunctions">Documenting functions</a>
<li><a href="#readability">Writing readable code</a>
</ol>
<h2 id="divingin">Diving in</h2>
<p class="fancy">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__":
<tr><th>Weakly typed</th><td>C, Objective-C</td><td>JavaScript, Perl 5, PHP</td></tr>
<tr><th>Strongly typed</th><td>Pascal, Java</td><td>Python, Ruby</td></tr>
</table>
<h2 id="documentingfunctions">Documenting functions</h2>
<h2 id="readability">Writing readable code</h2>
FIXME
<p>You can document a Python function by giving it a <code>docstring</code>. In this program, the <code>approximate_size</code> function has a <code>docstring</code>:
<pre><code>def approximate_size(size, a_kilobyte_is_1024_bytes=True):
"""Convert a file size to human-readable form.