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 ‣
-❝ 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
humansize module, you're just grabbing one of the data structures it defines: the list of "SI" (powers-of-1000) suffixes.
-{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'.
+{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":