Conventions used
There are a number of text conventions used and formatting specificities throughout this book.
Most of the code has been automatically formatted
The formatting has been done using the Black tool, as is commonly done by Python developers for productivity reasons. So it might not look exactly like the code you would write yourself. But it is valid; it is a PEP 8-compliant code. The goal is to improve the readability of the code snippets.
So, some code snippets in the code files as well as in the book’s pages may look like the following:
State = Enum( "State", "NEW RUNNING SLEEPING RESTART ZOMBIE", )
Another example might be the following:
msg = ( f"trying to create process '{name}' " f"for user '{user}'" ) print(msg)
The code snippets in the book’s pages may be shortened
To improve readability, when there is a documentation string (docstring) for a function or class, and it is too long, we remove it from the code snippet in the book.
When some code (class or function) is too long to display on the chapter’s pages, we may shorten it, and refer the reader to the complete code in the file.
Note
In case of an issue with long commands, which are spread across several lines (with the ‘/
’ character as separator), you can reformat the long command text, removing the ‘/
’ character, to make sure that the command is correctly interpreted in the terminal.
Other conventions
Code in text
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Define the Logger
interface with a log
method.”
A block of code is set as follows:
class MyInterface(ABC): @abstractmethod def do_something(self, param: str): pass
Any command-line input or output is written as follows:
python3.12 –m pip install -–user mypy
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “It is one of the core concepts in object-oriented programming OOP that enables a single interface to represent different types.”
Tips or important notes
Appear like this.