diff --git a/iterators-and-generators.html b/iterators-and-generators.html index 54aac8c..2ab0dca 100644 --- a/iterators-and-generators.html +++ b/iterators-and-generators.html @@ -11,7 +11,7 @@ body{counter-reset:h1 11}

You are here: Home Dive Into Python 3

Iterators & Generators

-

East is East, and West is West, and never the twain shall meet.
Rudyard_Kipling +

East is East, and West is West, and never the twain shall meet.
Rudyard Kipling

 

Diving in

diff --git a/strings.html b/strings.html index b31edc3..d2ea691 100644 --- a/strings.html +++ b/strings.html @@ -163,7 +163,7 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):
  1. Rather than calling any function in the humansize module, you're just grabbing one of the data structures it defines: the list of "SI" (powers-of-1000) suffixes. -
  2. This looks complicated, but it's not. {0} would refer to the first argument passed to the format() method, si_suffixes. But si_suffixes is a list. So {0[0]} refers to the first item of the list which is the first argument passed to the format() method: 'KB'. Meanwhile, {1[0]} refers to the second item of the same list: 'MB'. Everything outside the curly braces — including 1000, the equals sign, and the spaces — is untouched. The final result is the string '1000KB = 1MB'. +
  3. This looks complicated, but it's not. {0} would refer to the first argument passed to the format() method, si_suffixes. But si_suffixes is a list. So {0[0]} refers to the first item of the list which is the first argument passed to the format() method: 'KB'. Meanwhile, {0[1]} refers to the second item of the same list: 'MB'. Everything outside the curly braces — including 1000, the equals sign, and the spaces — is untouched. The final result is the string '1000KB = 1MB'.

What this example shows is that format specifers can access items and properties of data structures using (almost) Python syntax. This is called compound field names. The following compound field names "just work":