PrintNumber | ErrorLocation | Error | Correction | DateAdded |
---|---|---|---|---|
1 | piv | Third Printing March 2010 | Fourth Printing November 2010 | 8/3/2009 |
1 | p7 | On UNIX, EOF is Ctrl+D; on Windows, its Ctrl+Z. | On UNIX, EOF is Ctrl+D; on Windows, its Ctrl+Z (or F6). | 11/2/2010 |
1 | p9 | End of NOTE add sentence: A backslash is never needed for code enclosed in (), [], or {}. |
fixed | 11/2/2010 |
1 | p13 | if len(sys.argv) != 2 # Check number of command line arguments : | if len(sys.argv) != 2: # Check number of command line arguments | 11/2/2010 |
1 | p21 | # a web server must be actively writing data to the log. should NOT be indented. |
fixed | 11/2/2010 |
1 | p27 | To specify an integer using octal, hexadecimal, or binary notation, precede the value with 0, 0x, or 0b, respectively (for example, 0644, 0x100fea8, or 0b11101010). |
To specify an integer using octal, hexadecimal, or binary notation, precede the value with 0o, 0x, or 0b, respectively (for example, 0o644, 0x100fea8, or 0b11101010). | 11/2/2010 |
1 | p36 | items = { 'number' : 42 'text' : "Hello World |
items = { 'number' : 42, 'text' : 'Hello World' |
11/2/2010 |
1 | p40 | The s.sort() method sorts the elements of a list and optionally accepts a key function and reverse flag, both of which must be specified as keyword arguments. | The s.sort() method sorts the elements of a list (all of which should be of a uniform type) and optionally accepts a key function and reverse flag, both of which must be specified as keyword arguments. | 11/2/2010 |
1 | p41 | Table 3.4: Sorts items of s in place. key is a key function. reverse is a flag that sorts the list in reverse order. key and reverse should always be specified as keyword arguments. |
Sorts items of s in place. key is a key function. reverse is a flag that sorts the list in reverse order. key and reverse should always be specified as keyword arguments. The items in s should all be of a uniform type. | 11/2/2010 |
1 | p44 | Table 3.5: Pads a string with zeros on the left up to the specified width. |
Pads a string with the 0 digit character on the left up to the specified width. | 11/2/2010 |
1 | p45 | Table 3.6: Returns a sequence of (key,value) pairs. |
Returns a sequence of all (key,value) pairs in m. | 11/2/2010 |
1 | p45 | Table 3.6: Returns a sequence of key values. |
Returns a sequence of all key values in m. | 11/2/2010 |
1 | p49 | In the example, we have passed f, a an instance of Foo, as the first argument. | In the example, we have passed f, an instance of Foo, as the first argument. | 11/2/2010 |
1 | p55 | x = A.__new__(A,args) is isinstance(x,A): x.__init__(args) |
x = A.__new__(A,args) if isinstance(x,A): x.__init__(args) |
11/2/2010 |
1 | p58 | Keep in mind that descriptions are optional and rarely need to be defined. | Keep in mind that descriptors are optional and are rarely defined directly. |
11/2/2010 |
1 | p58 | Table 3.17: Returns an attribute value or raises AttributeError |
Returns the value of an attribute on instance. If instance is None, self should be returned. | 11/2/2010 |
1 | p59 | For example, the following variations of extended slicing are all supported and might be useful for working with multidimensional data structures such as matrices and arrays: | For example, the following variations of extended slicing are all supported by Pythons syntax and are sometimes used to manipulate multidimensional data structures, such as matrices and arrays in third-party extensions, such as NumPy: | 11/3/2010 |
1 | p60 | x = _iter.next()(#_iter.__next__() in Python 3) | x = _iter.next() #_iter.__next__() in Python 3 | 11/3/2010 |
1 | p67 | v1,v2
, vn = s s should be in italic. |
v1,v2, , vn = s | 11/3/2010 |
1 | p68 | d = a[0:5:2] # d = [0,2] | d = a[0:5:2] # d = [0,2,4] | 11/3/2010 |
1 | p69 | a[2:] = [0] # a = [1,6,0] | a[:] = [7,8] # a = [7,8]. id(a) remains the same | 11/3/2010 |
1 | p72 | name = "Elwood" age = 41 r = "%(name)s is %(age)s years old" % vars() |
name = "Elwood" age = 41 r = "%(name)s is %(age)d years old" % vars() |
11/3/2010 |
1 | p72 | A more advanced form of string formatting is available using the s.format(*args, *kwargs) method on strings. | A more advanced form of string formatting is available using the s.format(*args, **kwargs) method on strings. | 11/3/2010 |
1 | p75 | Augmented assignment doesnt violate mutability or perform in-place modification of objects. Therefore, writing x += y creates an entirely new object x with the value x + y. | Augmented assignment may or may not perform in-place modification of an object depending on its implementation. Therefore, writing x += y might modify x in-place or create an entirely new object with the value x + y. | 11/3/2010 |
1 | p76 | from functools import partial f = partial(foo,1,2) # Supply values to x and y arguments of foo f(3) # Calls foo(1,2,3), result i |
from functools import partial f = partial(foo,1,2) # Supply values to x and y arguments of foo result = f(3) # Calls foo(1,2,3), result is 6 |
11/3/2010 |
1 | p78 | x < y, x <= y, Comparison, identity, and sequence membership tests x > y, x >= y, x == y, x != yy |
x < y, x <= y, Value comparison, object identity, and x > y, x >= y, sequence membership tests x == y, x != y, |
11/3/2010 |
1 | p79 | x is y, x is not y x in s, x not in s |
x is y, x is not y, x in s, x not in s |
11/3/2010 |
1 | p79 | minvalue = a if a <=b else b | minvalue = a if a <= b else b | 11/3/2010 |
1 | p85 | try: do something except Exception as e: error_log.write('An error occurred : %s\n' % e) |
try: do something except Exception as e: # error_log is previously opened file-like object error_log.write('An error occurred : %s\n' % e) |
11/3/2010 |
1 | p87 | Table 5.1: Bad indentation and missing entries. 1. UnboundLocalError should be indented under NameError like this: NameError UnboundLocalError 2. NotImplementedError should be indented under RuntimeError like this: RuntimeError NotImplementedError 3. OverflowError is missing from the table. Should appear after FloatingPointError. ArithmeticError Base for arithmetic exceptions FloatingPointError Failure of a floating-point operation OverflowError Integer value too large ZeroDivisionError Division or modulus operation with 0 4. WindowsError is missing from the table. Should appear indented under OSError. EnvironmentError Errors that occur externally to Python IOError I/O or file-related error OSError Operating system error WindowsError Windows-specific error |
fixed | 11/3/2010 |
1 | p90 | def __exit__(self,type,value,tb): if type is None: |
def __exit__(self,exctype,value,tb): if exctype is None: |
11/3/2010 |
1 | p101 | debug_log.write("%s returned %s\n" % (func.__name, r)) | debug_log.write("%s returned %s\n" % (func.__name__, r)) | 11/3/2010 |
1 | p103 | def countdown(n): print("Counting down from %d" % n) while n > 0: yield n n -= 1 return |
def countdown(n): print("Counting down from %d" % n) while n > 0: yield n n -= 1 return # Note: generators can only return None |
11/3/2010 |
1 | p104 | Moreover, if a program is currently iterating on generator, you should not call close() asynchronously on that generator from a separate thread of execution or from a signal handler. | Moreover, if a program is currently iterating on a generator, you should not call close() asynchronously on that generator from a separate thread of execution or from a signal handler. | 11/3/2010 |
1 | p107 | wwwlogs = find("www","access-log* | wwwlogs = find_files("www","access-log* | 11/3/2010 |
1 | p109 | g = [math.sqrt(x*x+y*y) # f = [2.23606, 5.0, 7.81024] for x,y in f |
g = [math.sqrt(x*x+y*y) #g = [2.23606, 5.0, 7.81024] for x,y in f |
11/9/2010 |
1 | p113 | It is common practice for the first statement of function to be a documentation string describing its usage. | It is common practice for the first statement of a function to be a documentation string describing its usage. | 11/9/2010 |
1 | p115 | result = eval(c2) # Execute it | result = eval(c2) # Evaluate it | 11/9/2010 |
1 | p122 | class Z(X,Y): pass # TypeError. # Can't create consistent method resolution order__ |
class Z(X,Y): pass # TypeError. # Can't create consistent method resolution order |
11/9/2010 |
1 | p123 | class Date(object): | import time class Date(object): |
11/9/2010 |
1 | p124 | return cls(t.tm_year, t.tm_month, t.tm_day) | return cls(t.tm_year, t.tm_mon, t.tm_day) | 11/9/2010 |
1 | p125 | print("%s, %s" % (self.name, x) | print("%s, %s" % (self.name, x)) | 11/9/2010 |
1 | p127 | class TypedProperty(object): def __init__(self,name,type,default=None): self.name = "_" + name self.type = type self.default = default if default else type() def __get__(self,instance,cls): return getattr(instance,self.name,self.default) |
class TypedProperty(object): def __init__(self,name,type,default=None): self.name = "_" + name self.type = type self.default = type() if default is None else default def __get__(self,instance,cls): return getattr(instance,self.name,self.default) if instance else self |
11/9/2010 |
1 | p129 | u = Upperstr("hello") # value is "HELLO" | u = Upperstr("hello") # u = "HELLO" | 11/9/2010 |
1 | p132 | For attribute lookup such as obj.name, the special method obj.__getattrribute__("name") is invoked. |
For attribute lookup such as obj.name, the special method obj.__getattribute__("name") is invoked. |
11/9/2010 |
1 | p137 | Although an abstract class can not be instantiated, it can define methods and properties for use in subclasses. | Although an abstract class cannot be instantiated, it can define methods and properties for use in subclasses. | 11/9/2010 |
1 | p139 | __metaclass__ = type # class Foo(metaclass=type) underscoring before and after metaclass is off. |
__metaclass__ = type # class Foo(metaclass=type) | 11/9/2010 |
1 | p139 | class DocMeta(type): def __init__(self,name,bases,dict): for key, value in dict.items(): # Skip special and private methods if key.startswith("__"): continue # Skip anything not callable if not hasattr(value,"__call__"): continue # Check for a doc-string if not getattr(value,"__doc__"): raise TypeError("%s must have a docstring" % key) type.__init__(self,name,bases,dict) |
class DocMeta(type): def __init__(self,name,bases,attrs): for key, value in attrs.items(): # Skip special and private methods if key.startswith("__"): continue # Skip anything not callable if not hasattr(value,"__call__"): continue # Check for a doc-string if not getattr(value,"__doc__"): raise TypeError("%s must have a docstring" % key) type.__init__(self,name,bases,attrs) |
11/9/2010 |
1 | p140 | class TypedMeta(type): def __new__(cls,name,bases,dict): slots = [] for key,value in dict.items(): if isinstance(value,TypedProperty): value.name = "_" + key slots.append(value.name) dict['__slots__'] = slots return type.__new__(cls,name,bases,dict) |
class TypedMeta(type): def __new__(cls,name,bases,attrs): slots = [] for key,value in attrs.items(): if isinstance(value,TypedProperty): value.name = "_" + key slots.append(value.name) dict['__slots__'] = slots return type.__new__(cls,name,bases,attrs) |
11/9/2010 |
1 | p147 | First, it is only possible import .py, .pyw, .pyc, and .pyo files from an archive. | First, the only file types that can be imported from an archive are .py, .pyc, .pyo, and .pyw. | 11/9/2010 |
1 | p150 | To do this, you can simply use the fully specified named (e.g., from Graphics.Primitives import lines) or use a package relative import like this: | To do this, you can simply use the fully specified name (e.g., from Graphics.Primitives import lines) or use a package relative import like this: | 11/9/2010 |
1 | p152 | setup(name = "spam", version = "1.0", py_modules = ['libspam'], packages = ['spampkg'], scripts = ['runspam.py'], ) alignment off |
setup(name = "spam", version = "1.0", py_modules = ['libspam'], packages = ['spampkg'], scripts = ['runspam.py'], ) |
11/9/2010 |
1 | p160 | Table 9.1: Returns an integer file descriptor. |
Returns the integer file descriptor or raises valueError if closed. | 11/9/2010 |
1 | p163 | To suppress or change the line ending, use the end=ending keyword argument. For example: | To suppress or change the line ending, use the end=ending keyword argument (Note: if you specify something other than a newline, you may have to flush sys.stdout to see the output.). For example: | 11/9/2010 |
1 | p164 | print form % { 'name': 'Mr. Bush', 'item': 'blender', 'amount': 50.00, } |
print form % { 'name': 'Mr. Bush', 'item': 'blender', 'amount': 50.00 } |
11/9/2010 |
1 | p165 | outf.write("".join(chunks) | outf.write("".join(chunks)) | 11/9/2010 |
1 | p173 | -Q arg wrong fonts |
fixed | 11/9/2010 |
1 | p191 | If you simply want to time a long-running Python program, the easiest way to do it is often just to run it until the control of something like the UNIX time command. | If you simply want to time a long-running Python program, the easiest way to do it is often just to run it under the control of something like the UNIX time command. | 11/9/2010 |
1 | p194 | Bad font for section headers. The "Understand Algorithms" and "Use the Built-In Types" headers should be typeset in the same font as used for the "Understand Your Program" header above. | fixed | 11/9/2010 |
1 | p203 | In certain circumstances, such comparisons may also raise an exception. |
In certain circumstances, such comparisons may also raise an exception (Python 3 only). | 11/9/2010 |
1 | p204 | enumerate(iter[, initial value) | enumerate(iter[, initial_value]) | 11/10/2010 |
1 | p206 | In Python 3, a prompt is printed to standard output and a single line of input is read without any kind of evaluation or modification. |
In Python 3, a prompt is printed to standard output and a single line of input is read without any kind of evaluation or modification. The returned line does not include a trailing newline character. | 11/10/2010 |
1 | p210 | Slice objects are also generated by the extended slice syntax a[i:i:k]. | Slice objects are also generated by the extended slice syntax a[i:j:k]. | 11/10/2010 |
1 | p213 | It should be noted that floating-point exception- handling is a tricky problem and only that this exception only gets raised if Python has been configured and built in a way that enables it. |
It should be noted that floating-point exception- handling is a tricky problem and that this exception only gets raised if Python has been configured and built in a way that enables it. |
11/10/2010 |
1 | p226 | Returns the string written by the dump() function. | Returns the byte string written by the dump() function. | 11/10/2010 |
1 | p226 | loads(string) Reads and returns the next value from the string string. |
loads(bytes) Reads and returns the next value from the byte string bytes. |
11/10/2010 |
1 | p227 | Same as dump(), but returns a string containing the pickled data. | Same as dump(), but returns a byte string containing the pickled data. | 11/10/2010 |
1 | p227 | loads(string) Same as load(), but reads the pickled representation of an object from a string. |
loads(bytes) Same as load(), but reads the pickled representation of an object from a byte string. |
11/10/2010 |
1 | p233 | By default, the value of repr(value) is printed to standard output and value is saved in the variable __builtin__._. displayhook can be redefined to provide different behavior if desired. |
By default, the value of repr(value) is printed to standard output and value is saved in the variable __builtins__._. The displayhook function can be redefined to provide different behavior if desired. | 11/10/2010 |
1 | p237 | The types module should not be used to refer the type of built-in objects such as integers, lists, or dictionaries. | The types module should not be used to refer to the type of built-in objects such as integers, lists, or dictionaries. | 11/10/2010 |
1 | p242 | if resultcache.has_key(x): | if x in resultcache: | 11/10/2010 |
1 | p259 | Table 15.1: 'c' 8-bit character char 1 |
Delete, not supported in Python 3 and using it in Python 2 is probably ill-advised anyways. | 11/10/2010 |
1 | p260 | b = array.array(a.typecode, (2*x for x in a)) # Create a new array from b | b = array.array(a.typecode, (2*x for x in a)) # Create a new array from a | 11/10/2010 |
1 | p283 | compile(str [, flags]) | compile(pattern [, flags]) | 11/10/2010 |
1 | p288-289 | The fieldname may include additional indexing and attribute lookup such as '0.name or '0[name]'. | The fieldname may include additional indexing and attribute lookup such as '0.name'or '0[name]'. | 11/10/2010 |
1 | p300 | symbol = "AIG" account = 12345 |
bad indent, fixed | 11/10/2010 |
1 | p300 | Here, the '?' placeholders are successively replaced with values from the tuple (symbol, account). |
Here, the '?' placeholders are successively replaced with values from the tuple (symbol, account). '?' can only be used for values, not other parts of the query, such as the command or table name. |
11/10/2010 |
1 | p311 | ...has the same meaning as described in the chapter introduction and is one... | ...has the same meaning as described in the previous section and is one... | 11/10/2010 |
1 | p311 | d.has_key(key) | key in d | 11/10/2010 |
1 | p313 | Feeds new string data to the compressor object, c. Returns a string of compressed data if possible. Because compression involves chunks of data, the returned string may not include all the data and may include compressed data from previous calls to compress(). |
Feeds new byte string data to the compressor object, c. Returns a byte string of compressed data if possible. Because compression involves chunks of data, the returned byte string may not include all the data and may include compressed data from previous calls to compress(). | 11/10/2010 |
1 | p314 | Flushes the internal buffers and returns a string containing the compressed version of all remaining data. | Flushes the internal buffers and returns a byte string containing the compressed version of all remaining data. | 11/10/2010 |
1 | p314 | Given a chunk of compressed data in the string data, this method returns uncompressed data. Because data is processed in chunks, the returned string may or may not include a decompressed version of everything supplied in data. | Given a chunk of compressed data in the byte string data, this method returns uncompressed data. Because data is processed in chunks, the returned byte string may or may not include a decompressed version of everything supplied in data. | 11/10/2010 |
1 | p314 | Returns a compressed version of the data supplied in the string data. compresslevel is a number between 1 and 9 (the default). | Returns a compressed version of the data supplied in the byte string data. compresslevel is a number between 1 and 9 (the default). | 11/10/2010 |
1 | p314 | Returns a string containing the decompressed data in the string data. | Returns a byte string containing the decompressed data in the byte string data. | 11/10/2010 |
1 | p316 | Last line: print pyfile |
print (pyfile) | 11/10/2010 |
1 | p333 | vars is a dictionary of additional values that can be used in '% expansions. | vars is a dictionary of additional values that can be used in '%' expansions. | 11/10/2010 |
1 | p349 | except IOError,e: print "Unable to acquire lock", e |
except IOError as e: print "Unable to acquire lock %s" % e) |
11/10/2010 |
1 | p356 | format = "%(levelname)-10s %(asctime)s %(message)s" | format = "%(levelname)-10s %(asctime)s %(message)s", | 11/10/2010 |
1 | p398 | For example, '/home/user/foo' gets split into ('/home/ user', 'foo'). | For example, '/home/user/foo' gets split into ('/home/user', 'foo'). | 11/10/2010 |
1 | p406 | Puts the current process to sleep for secs seconds. | Puts the calling thread to sleep for secs seconds. | 11/10/2010 |
1 | p408 | key is a predefined handle such as HKEY_CURRENT_USER or HKEY_ USERS. | key is a predefined handle such as HKEY_CURRENT_USER or HKEY_USERS. | 11/10/2010 |
1 | p414 | Theres a joke attributed to Jason Whittington that goes as like this: Why did the multithreaded chicken cross the road? to To other side. get the. | Theres a joke attributed to Jason Whittington that goes like this: Why did the multithreaded chicken cross the road? to To other side. get the. | 11/10/2010 |
1 | p415 | For example, a coroutine is a function that can receive and processe messages that are sent to it. | For example, a coroutine is a function that can receive and process messages that are sent to it. | 11/10/2010 |
1 | p416 | The arguments in the constructor should always been specified using keyword arguments. | The arguments in the constructor should always be specified using keyword arguments. | 11/10/2010 |
1 | p417 | It should also be noted that on Windows, you will probably need to run the preceding examples in the command shell (command.exe) instead of a Python IDE, such as IDLE. | It should also be noted that on Windows, you will probably need to run the preceding examples in the command shell (cmd.exe) instead of a Python IDE, such as IDLE. | 11/10/2010 |
1 | p426 | Normally, processes are completed isolated from each other with the only means of communication being queues or pipes. | Normally, processes are completely isolated from each other with the only means of communication being queues or pipes. | 11/10/2010 |
1 | p465 | def send(self,bytes): while bytes: evt = yield WriteWait(self.sock) nsent = self.sock.send(bytes) bytes = bytes[nsent:] |
def send(self,data): while data: evt = yield WriteWait(self.sock) nsent = self.sock.send(data) data = data[nsent:] |
11/10/2010 |
1 | p493 | Redefine this method if you want to verify the connection before any further processing. This is what you define if you wanted to implement a firewall or perform some other kind of a validation. Finally, addition server features are available through the use of mixin classes. |
Method that is called to verify the connection before any further processing. By redefining this method, you can implement a firewall or perform other kinds of a validation. Finally, additional server features are available through the use of mixin classes. |
11/10/2010 |
1 | p497 | Attempts to abort a file transfer that is in progress. This may or may not work depending the remote server. |
Attempts to abort a file transfer that is in progress. This may or may not work depending on the remote server. | 11/10/2010 |
1 | p518 | Installs a different opener object for use as the global URL opener used by urlopen(). opener is usually of an opener object created by build_opener(). | Installs a different opener object for use as the global URL opener used by urlopen(). opener is usually an opener object created by build_opener(). | 11/10/2010 |
1 | p532 | The topics of web frameworks is far beyond the scope of this book, but http://wiki.python.org/ moin/WebFrameworks is a good starting point for finding more information. |
The topic of web frameworks is far beyond the scope of this book, but http://wiki.python.org/ moin/WebFrameworks is a good starting point for finding more information. |
11/10/2010 |
1 | p536 | ('text/html', {'a':'hello', 'b':'world'}). parse_multipart(fp, pdict) |
('text/html', {'a':'hello', 'b':'world'}). |
11/10/2010 |
1 | p538 | 'confirmation: ': confirmation, | 'confirmation' : confirmation, | 11/10/2010 |
1 | p570 | ile is a filename or an already-open file object. | file is a filename or an already-open file object. | 11/10/2010 |
1 | p588 | sched Event scheduler |
Delete, already listed on p587. | 11/10/2010 |
1 | p624 | >>> foo.__annotations__ {'y': 4, 'x': 3, 'return': 5} >>> |
>>> foo.__annotations__ {'y': 2, 'x': 1, 'return': 3} >>> |
11/10/2010 |
1 | p638 | For Python 3, especially, it is critically to report bugs, performance problems, and other issues. | For Python 3, especially, it is critically important to report bugs, performance problems, and other issues. | 11/10/2010 |
1 | p686 | numeric type coercision, 66-67 | numeric type coercion, 66-67 | 11/10/2010 |
1 | p695 | readline() method of IOBase objects, 349 of StreamReder objects, 278 readlines() method of IOBase objects, 349 of StreamReder objects, 278 |
readline() method of IOBase objects, 349 of StreamReader objects, 278 readlines() method of IOBase objects, 349 of StreamReader objects, 278 |
11/10/2010 |
1 | p697 | reset() method of HTMLParser objects, 562 of IncrementalDecoder objects, 279 of IncrementalEncoder objects, 278 of StreamReder objects, 278 |
reset() method of HTMLParser objects, 562 of IncrementalDecoder objects, 279 of IncrementalEncoder objects, 278 of StreamReader objects, 278 |
11/10/2010 |
1 | p712 | encoding and decoing, 165 | encoding and decoding, 165 | 11/29/2010 |