agezerlis (11) [Avatar] Offline
#1
Hi Vern,

Thanks for your kind words. I have finally written up the remaining corrections/suggestions. Given below are errata on chapters 15 to 24, along with a few stray ones from earlier chapters that I didn't catch before.

This time I also have a couple of questions! They are both connected to points I mention below in the relevant comments.

1) p. 202: you say that a module function has the functionality of a class method. Could you please show this in an example, preferably using the the total_area function discussed on pp. 192-193?

2) p. 219: why doesn't "__init__" need to have a line that says "self.master = master"? Maybe Frame has a variable by that name?

In closing, another question, but of a different kind: when the 2nd printing comes out, do people (like me) who bought the 1st printing get a free PDF from Manning?

Cheers,
Alex Gezerlis


------------------


p. 31 "Other special attribute methods permit": this should say "Other special method attributes permit".

p. 31 "when you’re ready to move on to the chapters in part 4 [...] before you move on to the chapters in part 4": the material covered in chapter 3 is more or less equivalent to the topics that are introduced in part 2. Part 3 is completely new stuff, so both of these references should mention "part 3", not "part 4".

p. 140 "Fortunately, the directory where the script is is appended as the first string in sys.path.": given OED's definition of append ("3. To add in writing by way of supplement or appendix.") I think it would be more appropriate to use here the word "prepend" -- "Chiefly Computing. trans. To add at the beginning, to prefix, prepose; esp. to add or append (a character, string, file, etc.) at the front of an existing string, file, etc.".

p. 144 "This is done here in the print statement.": this should say "in the print function call.".

p. 164 "print("A line from the print statement")": this should say "print("A line from the print function call output")".

p. 188 "than the previous print statement": this should say "than the previous print function call".

p. 188 "in the same manner as local method function variables": this should say either "in the same manner as local method variables" or "in the same manner as local function variables".

p. 189 "with one call on the circle class": this should be capitalized, "Circle".

p. 189 "Then, calls to circle would work with": similarly, "Circle".

p. 190 "make a direct call to it as a normal Python": I guess this was supposed to be "make a direct call to it as a normal Python function".

p. 190-192 There are six instances of pi appearing as 3.1415899999999999 and one as 3.140000000000001. These should be 3.14159 and 3.14 respectively.

p. 192 "If you want to change the value of a class variable, access it through the class name, not through the instance variable self.": This is the truth, but it is not the whole truth: we can change the value of a class variable through the instance variable self if we use self.__class__. In your example this would be something like c1.__class__.pi = 3.1 (or c2.__class__.pi = 3.1).

p. 193 "circle module: contains the Circle class.": this should say "circle_cm module: contains the Circle class.". The circle module was defined on the previous page.

p. 194 "You can use cls instead of self.__class__": I don't really understand this. Since "total_area" does not take "self" as a parameter, we would not be able to use "self.__class__" even if we wanted to. Perhaps what you meant to say was that in contradistinction to the case of the static method shown above, "You can use cls instead of Circle".

p. 195 "you can see in the bolded code in the Circle and Square classes.": there is no bolded code in these classes.

p. 195 "a method that isn’t defined in the base classes but is defined in the superclass": the word "superclass" and the phrase "base class" are synonyms. You probably meant to say "a method that isn’t defined in the derived classes but is defined in the superclass".

p. 196 "Inheritance allows an instance to inherit attributes of the class.": the way it is right now, this sentence is too vague. Perhaps you meant to say "Inheritance allows an instance to inherit attributes of the base class.".

p. 198 "What specifically happens is that _classname is appended to the variable name": as I pointed out above in connection with p. 140, here it is probably more appropriate to say "prepended" instead of "appended".

p. 198 "If someone wanted to, they could access the value.": it is perhaps worth mentioning here that (in keeping with what is discussed in the appendix, on p. 317) one could print the private variable from outside by saying "print(m._Mine__y)".

p. 199 "93.200000000000003": the output in Python 3.1 is "93.2".

p. 200 Fig. 15.2: In the bottom row, the third from the right box says "Private instance" but it should say "Private instance variables".

p. 200 Fig. 15.2: In the top row, the second from the right box says "Superclass class variables" but it should say "Private superclass methods".

p. 201 "(but use SC.siv for assignment)": this appears on the line that defines self.siv. It is quite baffling: in all other cases when you say "use ClassName.variable for assigment" you do that for class variables, but siv is not a class variable, it's an instance variable. If this is changed, its output should also be changed. Also, you do not say "use SC.scv for assigment" when you define the superclass class variable scv.

p. 201 "self.iv = 'instance variable: self.xi'": I see no reason why this should be "self.xi" and not "self.iv". If this is changed, then it should also be changed in the output, on p. 203.

p. 201 Next to "variable print(lv)" you have an arrow that says "Instance variable". This should say "Local variable".

p. 202 Next to "print(self.__pm())" you have an arrow that says "Private module". This should say "private method".

p. 202 Next to "print(self.scv)" you have an arrow that says "Superclass variable through instance". This should say "Superclass class variable through instance".

p. 202 "the module function mf, (which, as described in a previous section, we can use to provide a class method functionality)": I don't believe this was described in a previous section. The only way we have seen of getting a class method is by using the @classmethod decorator.

p. 203 "two methods M and M2, along with the mangled names of the private method __PM": these names should be changed to "m", "m2", and "_pm", respectively.

p. 203 "superclass method SM. It also contains the mangled names of private superclass method __SPM and private superclass class variable __spcv": these names should be changed to "sm", "_spm", and "_pscv", respectively.

p. 203 "superclass method: self.SM()": this should be changed to "superclass method: self.sm()".

p. 207 "the inheriting class behaves like a synthesis of its own definitions and all of its ancestor’s definitions.": this needs an extra "s", i.e. "ancestors's".

p. 207 "the class definitions y look like this": the "y" should be removed.

p. 217 "the corners of a 2?×?2 grid [...] 2×?2": both of these should be "2x2".

p. 221-222 "QT is a rich and powerful GUI framework and also has QT Designer": both of these occurrences of "QT" should be changed to "Qt".

p. 219 "command=self.master.destroy": you do not explain why you need to do this instead of "self.destroy" (this does not kill the main window). This is connected to the fact that when you create the label and two buttons you do not explain why you say "Label(self" and "Button(self", though you could be saying (to be consistent with the original form of the example) "Label(self.master" and "Button(self.master". While we're on this subject, shouldn't "__init__" have a line that says "self.master = master"? On the other hand, right now it doesn't and it seems to be working just fine without it.

p. 219 "because increment_counter is now an instance variable": this should say "because count_value is now an instance variable".

p. 226 "match many different specific strings..": one of the two periods should be removed.

p. 227 "is given in the appendix at the end of this book": this should say "is given in the Python documentation".

p. 227 "not with embedded -
sequences": I think the "-" should be deleted.

p. 229 "let’s assume for right now that that first names": one of the instances of "that" should be removed.

p. 230 "( (?P<middle>([-a-zA-Z]+)))?": perhaps there is an extra set of parentheses here. "( (?P<middle>[-a-zA-Z]+))?" would work just as well, and would be consistent with the other cases. If you do change this here, you should also change it on p. 231.

p. 231 "print('Name:', firstname, middlename, lastname,' Number:', phonenumber)": you probably used this indentation for page-setting reasons. However, given where it's currently placed, you're trying to access the "firstname", "middlename", "lastname", and "phonenumber" variables even when "result == None".

p. 235 Figure 18.1 has two instances of "constants.pi". Given the discussion in the text, as well as Figure 18.2, I think it's obvious that this should say "constants.py".

p. 236 One of the leaves in Figure 18.2 says "__init.py__": this should be "__init__.py".

p. 238 "These two lines are printed out by print statements in the __init__.py files": this should say "print function calls".

p. 239 "print "version is", version": this should be "print("version is", version)".

p. 239 "print h()": similarly, this should be "print(h())".

p. 243 "We have any easy way of finding out": this should say "an" instead of "any".

p. 245 "The issubclass function is only for class types.": this should be in the same font as the text (with the exception of the name "issubclass".)

p. 248 "Color: R={0:d}, G={1:d}, B={2:d}": I don't think you've shown this way of using the format method before (i.e. ":d" inside the positional parameters).

p. 249 "all of which are defined in the reference appendix": this should say "in the Python documentation".

p. 251 "implementing a full-list emulation class": this makes it seem like you're interested in an entity called a "full list". In reality, you're interested in a "list-emulation class" which is full, so "implementing a full list-emulation class".

p. 252 "special function attributes": you list this in your errata. I believe this isn't necessarily wrong. It's also used in "Dive Into Python 3" (section 17.25) and in "Core Python Programming" (exercise 14.11). (The official documentation isn't much help here, since it calls these "special method names".) If you do think it's an erratum, then you should also change it on p. 256: " all of the appropriate special function attributes".

p. 253 "The accesses of elements of x in the print statement": this should say "in the print function call".

p. 253 "The last line uses __getitem__ to unpack the first four items in x and then pack them into the variables a, b, c, d, and e, respectively.": first, the unpacking and packing does not take place in the last line, but in the second to last line. Second, x.elements has five elements, which are then packed into the five variables a, b, c, d, and e, so I don't understand why the text says "the first four items in x".

p. 255 "super().__init__(initial_list)": this is the first thing you do in the __init__ method of class TypedUserList. On the other hand, on p. 254 that same call is the last thing you do in the __init__ method of class TypedListList. Is there a reason for this discrepancy? Since the rest of the body of the __init__ method (in both cases) simply checks for validity, I suppose it makes more sense to call the parent's constructor at the end of the checks.

p. 257 "Note that the type of the class spam is 'type'.": this should say "Spam".

p. 257 "Spam = type("Spam", (object,), {'__init__': init, 'show': show})": given that this is a book on Python 3, all the classes shown up to this point were new-style classes. As a result, all classes inherit from "object". However, this is the first point in the book where this fact is shown . Perhaps this warrants a short explanation.

p. 257 "and the type of spam is still 'type'.": this should say "Spam".

p. 257 "def __init__(cls, name, bases, methods):" and "type.__init__(cls, name, bases, methods)": you have described above that the last item is a dictionary of attributes, not methods. Thus, it would be best in both cases if the last argument was renamed to something like "dict" (like on p. 25smilie.

p. 261 "The abstractmethod function sets a function attribute": perhaps this was supposed to be "The abstract method sets a function attribute"?

p. 262 "def getx(self): # read only": I can't help but think that this comment belongs with "def readx(self):". getx is a normal method, so there's no real reason to explain that it doesn't write. What is new in this example is that readx is an abstract property which is read-only (and also that getx and setx can be combined to provide a read-write property).

p. 271 "There are number of test asserts in TestCase": I think you're missing an "a".

p. 272 "Let’s assume that we changed the value of the __getitem__ test so that it would fail:" the first two lines of the output following this sentence only appear if you give the -v option.

p. 272 "self.assertEqual(self.aTypedList[1], 3)": this is part of the assertion error output. It is consistent with the code sample you have provided, but not with the text in Listing 21.3. There you say "self.assertEqual(self.a_typedlist[1], 2)", i.e. after the change from "2" to "3" the variable would still be called "a_typedlist", not "aTypedList".

p. 272 "This is done most easily by using the TestSuite, TestLoader, and TestRunner classes.": the word "TestRunner" should be "TextTestRunner".

p. 272 "unittest.defaultTestLoader().loadTestsFromTestCase(TestTypedList)": you say "defaultTestLoader()" but you also mention that defaultTestLoader is an instance. In that case shouldn't the parentheses be missing?

p. 275 "an_iterator.next()" and "next(an_iterator)": these are not mentioned anywhere else in the book. If they're here for the sake of completeness, then other things like string formatting and metaclasses also belong here.

p. 276 "infile = open(filename, "rb")": for this to be consistent with the code shown in Listings 22.2 and 22.3, it should say "infile = file(filename, "rb")".

p. 277 "print "%d cents contains %d quarters" % (cents, quarters)": Listings 22.2 and 22.3 use "%s". At least one of these needs to be changed.

p. 277 "getting a string from the user, opening a file, reading from the file, comparing the contents of the file to a string, appending a string, handling errors, and so on.": I cannot see where the contents of a file were compared to a string, or where the code appends a string.

p. 277 "there is no long an integer type in Python 3.x": the word "an" should be removed.

p. 281 "Migrating the code Python 3 is probably the ideal long-term solution": this should say "to Python 3".

p. 287 "This section surveys your options when you need to do something that isn’t in the standard library.": this section ends with that sentence, so it doesn't really survey such options.

p. 288 "The current system uses distutils, which is a module in the standard library.": here you call distutils a "module", but on p. 145 you had called it a "package".

p. 288 "followed by the location you want use": this should say "you want to use".

p. 289 "Csmilieocuments and Settingsvernlib": the Linux example showed the libraries as being at "/home/vern/lib/python" so shouldn't the Windows example also end with "python"?

p. 291 "The specification calls for the use of a connection object [...] is a connection object. Getting a connection object requires [...] which will direct the connection object to parse": looking at PEP 249, it looks like "connection" should be capitalized.

p. 291 "or the use of cursor objects to manage [...] The second step is to create a cursor object": similarly, I think this should be "Cursor".

p. 291 "calling the connect function with the name of file that will be used": this should say "the name of the file".

p. 293 "Cursor = conn.cursor()": you probably capitalized this to make it look slightly different from the cursor method. However, in the other rows of this table (as well as in the examples in the text) you simply call it "cursor".

p. 299 "to print to StringIO object": this should say "to print to the StringIO object".

p. 301 "we need to get the PATH_INFOsmilieATH_INFO from the request": I think this should be simply "PATH_INFO".

p. 333 The entry on shelves has a sub-entry on "key membership (has_key)". This should either be changed to "key membership (in)" or it should removed.
naomi.ceder (134) [Avatar] Offline
#2
Re: Errata list for chapters 15-24
Hi Alex,

> Thanks for your kind words. I have finally written up
> the remaining corrections/suggestions. Given below
> are errata on chapters 15 to 24, along with a few
> stray ones from earlier chapters that I didn't catch
> before.

Many thanks! I'll work through these and send them along.

> This time I also have a couple of questions! They are
> both connected to points I mention below in the
> relevant comments.
>
> 1) p. 202: you say that a module function has the
> functionality of a class method. Could you please
> show this in an example, preferably using the the
> total_area function discussed on pp. 192-193?

Hmmm... that may need more clean-up. That comment almost should be removed.
However, it's referring to the fact that the only thing really special about a class method in Python is that it is passed the class as an argument. If you want to use an unbound function instead, you just need to explicitly pass it the class and you get the same effect (if you can follow the loss of spaces):

<pre>
"""circle module: contains the Circle class."""

def total_area_external(cls):
total = 0
for c in cls.all_circles:
total = total + c.area()
return total

class Circle:

"""Circle class"""
# Variable containing a list of all circles which have been created.
all_circles = []
pi = 3.14159
def __init__(self, r=1):
"""Create a Circle with the given radius"""
self.radius = r
self.__class__.all_circles.append(self)
def area(self):
"""determine the area of the Circle"""
return self.__class__.pi * self.radius * self.radius

>>> import circle_cm
>>> c1 = circle_cm.Circle(1)
>>> c2 = circle_cm.Circle(2)
>>> circle_cm.Circle.total_area()
15.70795
>>> c2.radius = 3
>>> circle_cm.Circle.total_area()
31.415899999999997
</pre>

> 2) p. 219: why doesn't "__init__" need to have a line
> that says "self.master = master"? Maybe Frame has a
> variable by that name?

Yep, which is why master is passed to the Frame.__init__ call.

> In closing, another question, but of a different
> kind: when the 2nd printing comes out, do people
> (like me) who bought the 1st printing get a free PDF
> from Manning?

At the moment, registered ebook owners are emailed when a new version is ready and then have 5 days to download the new version. Manning is moving towards a system where ebook owners have a login and then can access the latest version of their ebooks whenever they want. In any case, if you don't get an updated version eventually, let me know and I'll make sure you do! smilie

That said, as "just" the author smilie I can't say when they'll put out a new version. Since it will no doubt be linked with the need to do another printing, I'm hoping it will be sooner rather than later!

> Cheers,
> Alex Gezerlis

Cheers,
Vern
naomi.ceder (134) [Avatar] Offline
#3
Re: Errata list for chapters 15-24
Ooops... the call to that function in both cases should be:

>>> circle_cm.Circle.total_area_external(circle_cm.Circle)

Vern