Errata

Python for DevOps

Errata for Python for DevOps

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed, Other Digital Version Page Example 3-2. Parsing with sys.argv
p.63

Incorrect variable name inside the if __name__ block of code.
When executing the code python interpreter error:

File "<BASE_PATH>/sys_argv.py", line 34, in <module>
say_it(greeting, name)
NameError: name 'name' is not defined

Following change fixed the issue:

#!/usr/bin/env python3

"""
Simple command-line tool using sys.argv
"""

import sys

def say_it(greeting, target):
message = f'{greeting} {target}'
print(message)

if __name__ == '__main__':
greeting = 'Hello'
name = 'Joe' # <--- CHANGED from target to name

if '--help' in sys.argv:
help_message = f"Usage: {sys.argv[0]} --name <NAME> --greeting <GREETING>"
print(help_message)
sys.exit()

if '--name' in sys.argv:
# Get position after name flag
name_index = sys.argv.index('--name') + 1
if (name_index < len(sys.argv)):
name = sys.argv[name_index]

if '--greeting' in sys.argv:
# Get position after greeting flag
greeting_index = sys.argv.index('--greeting') + 1
if (greeting_index < len(sys.argv)):
greeting = sys.argv[greeting_index]

say_it(greeting, name)

Manoj Patel  Mar 13, 2022 
PDF Page 21
examples for general note

The Chinese example 'Nǐn hǎo' has the wrong tone for 'Nin'. The example is confusing the more common, informal 'you', which is 'nǐ' (which is third tone) with respectful 'you' (nín) which is second tone (í) and not third tone (ǐ). Should either change 'Nǐn' to 'Nín' or use 'Nǐ'.

Anonymous  Feb 18, 2021 
Printed Page 148
Code block, import/from statement block

from category import CAT
from new_picture_products import PICTURES

What do these lines do? Where are the associated CAT and PICTURES.

Code example seems incomplete.

John MacTavish  Sep 16, 2020 
Printed Page 149
In the code block: if __name__ == '__main__'

Same question as from page 148:

The code block contains the reference:

from new_pic_category import PRODUCT

However the contents of the file/code block, new_pic_category appear to be missing so it is unclear what object is to be included. Based on the name PRODUCT I suspect that it may be a constant per PEP8.

https://www.python.org/dev/peps/pep-0008/#constants

Thanks.

John MacTavish  Sep 17, 2020