0% found this document useful (0 votes)
32 views4 pages

Dead Simple Python: Essential Corrections

The document lists various errata for the book 'Dead Simple Python' by Jason C. McDonald, detailing specific errors and their corrections across multiple pages. Corrections include clarifications on code examples, syntax adjustments, and updates to programming concepts. Each entry specifies the page number, the error, and the corresponding correction.

Uploaded by

arnesh052006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Dead Simple Python: Essential Corrections

The document lists various errata for the book 'Dead Simple Python' by Jason C. McDonald, detailing specific errors and their corrections across multiple pages. Corrections include clarifications on code examples, syntax adjustments, and updates to programming concepts. Each entry specifies the page number, the error, and the corresponding correction.

Uploaded by

arnesh052006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Dead Simple Python

Idiomatic Python for the Impatient Programmer


by Jason C. McDonald

Errata updated to print 2


Print
Page Error Correction
corrected

5 Nuitka can be used to transpile Python code C and C++ . . . Nuitka can be used to transpile Python code to C and C++ . . . Print 2

15 On Fedora, RHEL, or CentOS, you can run this: On Fedora, RHEL, or CentOS, you can run this: Print 2

sudo dnf python3 python3-pip sudo dnf install python3 python3-pip

30 If I ran the linter again, I’d only see the other two linter errors: If I ran the linter again, I’d only see the other three linter errors: Print 2

47 On Fedora, RHEL, or CentOS, you can run this: Print 2


foo %= 51 # value is now 42.0 (144.0 % 15)
foo %= 51 # value is now 42.0 (144.0 % 51)

52 The assignment expression is enclosed in parentheses for readability, although The parentheses in the assignment expression is important, as it controls what Print 2
I technically could have omitted them. part of the expression is stored as the value of eggs. If I omitted the
parentheses, the value True would be stored instead of an integer.

57 First, if you want to wrap an expression in literal curly braces, you must use two curly First, if you want to wrap an expression in literal curly braces, you must use two curly Print 2
braces ({{ }}) for every one you want displayed: braces ({{ }}) for every one you want displayed, plus an additional pair to enable
substitution.
answer = 42
print(f"{{answer}}") # prints "{42}" answer = 42
print(f"{{{{answer}}}}") # prints "{{42}}" print(f"{{{answer}}}") # prints "{42}"
print(f"{{{{{{answer}}}}}}") # prints "{{{42}}}" print(f"{{{{{answer}}}}}") # prints "{{42}}"
print(f"{{{{{{{answer}}}}}}}") # prints "{{{42}}}"

114 Print 2
Hot: ["Lettuce", "Tomato", "Cheese", "Beef", "Salsa"] Hot: ["Lettuce", "Tomato", "Beef", "Salsa"]
Mild: ["Lettuce", "Tomato", "Cheese", "Beef"] Mild: ["Lettuce", "Tomato", "Beef"]
Default: ["Lettuce", "Tomato", "Cheese", "Beef"] Default: ["Lettuce", "Tomato", "Beef"]

149 In this chapter, I’ll cover the essentials of object-oriented programming in Python: In this chapter, I’ll cover the essentials of object-oriented programming in Python: Pending
creating classes with attributes, modules, and properties. creating classes with attributes, methods, and properties.
Print
Page Error Correction
corrected

162 In this case, I assume this is some sort of string, which I run through the static In this case, I assume this is some sort of string, which I run through the class method Print 2
method _encode() I defined earlier and then store in the list self._secrets. encrypt() I defined earlier and then store in the list self._secrets.

162 You actually don’t need to define a deleter if you have no need for special behavior You actually don’t need to define a deleter if you have no need for special behavior Print 2
when the decorator is deleted. Consider what you want to happen if del is called on when the property is deleted. Consider what you want to happen if del is called on
your decorator, such as when you are deleting an associated attribute that the your property, such as when you are deleting an associated attribute that the property
property controls; if you can’t think of anything, skip writing the deleter. controls; if you can’t think of anything, skip writing the deleter.

184 If case exceptions . . . In case exceptions . . . Print 2

224 Insertion Counter is designed specifically for counting hashable objects; the object is the key, and Print 2
the count is an integer value. Other languages call this type of collection a multiset.
Multisets are not the same as counters, but are sometimes used in place of
them, as a side effect of how multisets work.

318 Figure update Print 2

326 [Link]() Creates an empty file at path. Normally, nothing happens if it [Link]() Creates an empty file at path. If one already exists, it updates Print 2
already exists. If the optional exist_ok= argument is False and the the access timestamp on file, but does nothing else. If the
file exists, a FileExistsError is raised. optional exist_ok= argument is False and the file exists, a
FileExistsError is raised.

358 Print 2
left = int.from_bytes(left, byteorder=byteorder) left = int.from_bytes(left, byteorder, signed=False)
right = int.from_bytes(right, byteorder=byteorder) right = int.from_bytes(right, byteorder, signed=False)

359 Print 2
result = left & right result = left & right
return result.to_bytes(size, byteorder, signed=True) return result.to_bytes(size, byteorder, signed=False)

Listing 12-38: bitwise_via_int.py:3 Listing 12-38: bitwise_via_int.py:3


I bind the result of the bitwise operation to result. Finally, I convert result back to a I bind the result of the bitwise operation to result. Finally, I convert result back to a
bytes object, using the size I determined earlier, the byteorder passed to my bytes object, using the size I determined earlier, and the byteorder passed to my
function, and signed=True to handle conversion of any possible negative integer function. I can safely assume signed=False, as left and right can only ever be
values. I return the resulting bytes-like object. positive integers.
Print
Page Error Correction
corrected

450 Print 2
from functools import singledispatchmethod from functools import singledispatchmethod
from typing import overload class Element:
class Element: # --snip--
# --snip--

450– In this case, I’ll create two more versions of the function: one that works with a string In this case, I’ll create three more versions of the function: one that works with a Print 2
451 argument and another that works with either an integer or a floating-point string argument, another that works with a floating-point number, and a third
number argument: with an integer:

@__eq__.register @__eq__.register
def _(self, other: str): def _(self, other: str):
return [Link] == other return [Link] == other

@overload @__eq__.register
def _(self, other: float): def _(self, other: float):
... return [Link] == other
@__eq__.register
def _(self, other: int): @__eq__.register
return [Link] == other def _(self, other: int):
return [Link] == other
The first of these methods accepts a string argument. The first parameter, the one
being switched on, is annotated with a type hint for the expected type, which is a The first of these methods accepts a string argument. The first parameter, the one
string (str) in this first case. being switched on, is annotated with a type hint for the expected type, which is a
The second method here accepts either an integer or a float, and it is made string (str) in this first case. The second method here accepts a float, and the
possible with the @[Link] decorator. When type hinting, you can mark one third an int.
or more function headings with @overload, to indicate that they overload an upcoming When type hinting, you can ordinarily mark one or more function headings with a
function or method with the same name. The Ellipsis (...) is used in place of the suite special @[Link], to indicate that they overload an upcoming function or
of the overloaded method, so it can instead share the suite of the method below it. method with the same name. The Ellipsis (...) is used in place of the suite of the
The function or method not decorated with @overload must come immediately after overloaded method, so it can instead share the suite of the method below it. The
all the overloaded versions thereof. function or method not decorated with @overload must come immediately after all the
overloaded versions thereof. I first thought to use this here, since the second and
third functions had the same body. Unfortunately, @overload does not work with
other decorators, so I could not use this technique here.
Print
Page Error Correction
corrected

453 Print 2
def __str__(self): def __str__(self):
s = "" s = ""
formula = [Link]() formula = [Link]()
# Hill system # Hill system
if 'C' in [Link](): if 'C' in [Link]():
s += f"C{formula['C']}" s += f"C{formula['C']}"
del formula['C'] del formula['C']
if 1 in [Link](): if 'H' in [Link]():
s += f"H{formula['H']}" s += f"H{formula['H']}"
del formula['H'] del formula['H']

627 It can also be used on a number of Raspberry Pi and Ardunio microcontrollers, as It can also be used on a number of Raspberry Pi and Arduino microcontrollers, as Print 2
well as hardware from many other brands. well as hardware from many other brands.

You might also like