From da654d2ba08256e323c02767db7872c6c7fc671f Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sat, 28 Mar 2009 16:45:10 -0500 Subject: [PATCH] validation typos --- case-study-porting-chardet-to-python-3.html | 2 +- iterators-and-generators.html | 2 +- strings.html | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index 3ce320c..9aa22da 100644 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -1114,7 +1114,7 @@ tests\Big5\0804.blogspot.com.xml File "C:\home\chardet\chardet\latin1prober.py", line 126, in get_confidence total = reduce(operator.add, self._mFreqCounter) NameError: global name 'reduce' is not defined -

According to the official What's New In Python 3.0 guide, the reduce() function has been moved out of the global namespace and into the functools module. Quoting the guide: "Use functools.reduce() if you really need it; however, 99 percent of the time an explicit for loop is more readable." You can read more about the decision from Guido van Rossum's weblog: The fate of reduce() in Python 3000. +

According to the official What's New In Python 3.0 guide, the reduce() function has been moved out of the global namespace and into the functools module. Quoting the guide: "Use functools.reduce() if you really need it; however, 99 percent of the time an explicit for loop is more readable." You can read more about the decision from Guido van Rossum's weblog: The fate of reduce() in Python 3000.

def get_confidence(self):
     if self.get_state() == constants.eNotMe:
         return 0.01
diff --git a/iterators-and-generators.html b/iterators-and-generators.html
index a18154c..f075d9a 100644
--- a/iterators-and-generators.html
+++ b/iterators-and-generators.html
@@ -416,7 +416,7 @@ def plural(noun):
 

Thoroughly confused yet? Excellent. Let’s see how to call this iterator:

->>> from fibonacci2 import fib
+>>> from fibonacci2 import fib
 >>> for n in fib(1000):
 ...     print(n, end=' ')
 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
diff --git a/strings.html b/strings.html index b1de286..a8222ae 100644 --- a/strings.html +++ b/strings.html @@ -120,13 +120,13 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True): Returns: string """ - if size < 0: + if size < 0: raise ValueError('number must be non-negative') multiple = 1024 if a_kilobyte_is_1024_bytes else 1000 for suffix in SUFFIXES[multiple]: size /= multiple - if size < multiple: + if size < multiple: return "{0:.1f} {1}".format(size, suffix) raise ValueError('number too large')
@@ -203,7 +203,7 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):

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

if size < multiple:
+
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.