diff --git a/about.html b/about.html index 5a265ea..a2cce71 100644 --- a/about.html +++ b/about.html @@ -23,3 +23,5 @@ h1:before{content:""}

Send corrections and feedback to mark@diveintomark.org.

© 2001–9 ark Pilgrim + + diff --git a/dip3.css b/dip3.css index 08195b4..08de375 100644 --- a/dip3.css +++ b/dip3.css @@ -1,3 +1,59 @@ +/* + +"Dive Into Python 3" stylesheet + +vv-- begin MIT open source license --vv + +Copyright (c) 2009, Mark Pilgrim, All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +^^-- end MIT open source license --^^ + + +Classname Legend + +.w = "widgets" = wrapper block for hide/open/download links dynamically inserted into code listings +.b = "block" = internal block dynamically inserted into code listings +.d = "download" = download link for code listings +.p = "prompt" = command-line or interactive shell prompt within code listings +.q = "quote" = quote at beginning of each chapter +.f = "fancy" = first paragraph of each chapter (gets a fancy drop-cap) +.c = "centered" = centered footer text + +.note = "note/caution/important" = indented block for tips/gotchas/language comparisons +.baa = "best available ampersand" = wrapper block for ampersands + + +Acknowledgements & Inspirations + +"The Elements of Typographic Style Applied to the Web" ... http://webtypography.net/toc/ +"Setting Type on the Web to a Baseline Grid" ............. http://www.alistapart.com/articles/settingtypeontheweb +"Compose to a Vertical Rhythm" ........................... http://24ways.org/2006/compose-to-a-vertical-rhythm +"Use the Best Available Ampersand" ....................... http://simplebits.com/notebook/2008/08/14/ampersands.html +"Unicode Support in HTML, Fonts, and Web Browsers" ....... http://alanwood.net/unicode/ + +*/ + /* typography */ body,.w a{font:medium 'Gill Sans','Gill Sans MT',Corbel,Helvetica,Jara,'Nimbus Sans L',sans-serif;line-height:1.75;word-spacing:0.1em} pre,kbd,code,samp{font-family:Consolas,'Andale Mono',Monaco,'Liberation Mono','Bitstream Vera Sans Mono','DejaVu Sans Mono',monospace;font-size:medium;line-height:1.75;word-spacing:0} diff --git a/index.html b/index.html index cc66179..78ccab8 100644 --- a/index.html +++ b/index.html @@ -55,3 +55,5 @@ h1:before{content:""}

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

© 2001–9 ark Pilgrim + + diff --git a/notes.txt b/notes.txt index f900705..7d75fa1 100644 --- a/notes.txt +++ b/notes.txt @@ -19,6 +19,9 @@ http://www.alanwood.net/unicode/dingbats.html ‽ - interrobang ❝ - heavy double turned left comma quotation mark ornament ❞ - heavy double turned right comma quotation mark ornament +◉ - fisheye +⍥ - APL FUNCTIONAL SYMBOL CIRCLE DIAERESIS +※ - reference mark http://docs.python.org/dev/library/turtle.html http://svn.python.org/projects/python/trunk/Demo/turtle/ diff --git a/strings.html b/strings.html index 75ce490..79b58a3 100644 --- a/strings.html +++ b/strings.html @@ -146,10 +146,10 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True): "mark's password is PapayaWhip"

  1. No, my password is not really PapayaWhip. -
  2. There's a lot going on here. First, that's a method call on a string literal. Strings are objects, and objects have methods. Second, the whole expression evaluates to a string. Third, {0} and {1} are format specifiers, which are replaced by the arguments passed to the format() method. +
  3. There's a lot going on here. First, that's a method call on a string literal. Strings are objects, and objects have methods. Second, the whole expression evaluates to a string. Third, {0} and {1} are replacement fields, which are replaced by the arguments passed to the format() method.
-

The previous example shows the simplest case, where the format specifiers are simply integers. Integer format specifiers are treated as positional indices into the argument list of the format() method. That means that {0} is replaced by the first argument (username in this case), {1} is replaced by the second argument (password), &c. You can have as many positional indices as you have arguments, and you can have as many arguments as you want. But format specifiers are much more powerful than that. +

The previous example shows the simplest case, where the replacement fields are simply integers. Integer replacement fields are treated as positional indices into the argument list of the format() method. That means that {0} is replaced by the first argument (username in this case), {1} is replaced by the second argument (password), &c. You can have as many positional indices as you have arguments, and you can have as many arguments as you want. But replacement fields are much more powerful than that.

 >>> import humansize
@@ -179,20 +179,39 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):
 
 >>> import humansize
 >>> import sys
->>> "1MB = 1000{0.modules[humansize].SUFFIXES[1000][0]}".format(sys)
+>>> "1MB = 1000{0.modules[humansize].SUFFIXES[1000][0]}".format(sys)
 '1MB = 1000KB'

Here's how it works:

+

But wait! There's more! Let's take another look at that strange line of code from humansize.py: + +

if size < multiple:
+    return "{0:.1f} {1}".format(size, suffix)
+ +

{1} is replaced with the second argument passed to the format() method, which is suffix. But what is {0:.1f}? It's two things: {0}, which you recognize, and :.1f, which you don't. The second half (including and after the colon) defines the format specifier, which further refines how the replaced variable should be formatted. + +

+

Format specifiers allow you to munge the replacement text in a variety of useful ways, like the printf() function in C. You can add zero- or space-padding, align strings, control decimal precision, and even convert numbers to hexadecimal. +

+ +

Within a replacement field, a colon (:) marks the start of the format specifier. The format specifier “.1” means “round to the nearest tenth” (i.e. display only one digit after the decimal point). The format specifier “f” means “fixed-point number” (as opposed to exponential notation or some other decimal representation). Thus, given a size of 698.25 and suffix of 'GB', the formatted string would be '698.3 GB', because 698.25 gets rounded to one decimal place, then the suffix is appended after the number. + +

+>>> "{0:.1f} {1}".format(698.25, 'GB')
+'698.3 GB'
+ +

For all the gory details on presentation types, check the Format Specification Mini-Language in the official Python documentation. +

Note that (k, v) is a tuple. I told you they were good for something. @@ -342,6 +361,15 @@ is an object. You might have thought I meant that string variables are

  • Character encoding in HTML +

    On strings and string formatting: + +

    +

    © 2001–9 ark Pilgrim diff --git a/table-of-contents.html b/table-of-contents.html index ac8790f..b07caea 100644 --- a/table-of-contents.html +++ b/table-of-contents.html @@ -194,6 +194,7 @@ ul li ol{margin:0;padding:0 0 0 2.5em}

  • XML Processing
    1. ...major changes afoot... +
    2. lxml 2.2 officially supports Python 3
  • HTTP web services