June 2019
Beginner to intermediate
770 pages
19h 24m
English
Let's look at a somewhat more complex definition of a Blog class. This definition is repeated from Chapter 10, Serializing and Saving - JSON, YAML, Pickle, CSV, and XML, as well as Chapter 11, Storing and Retrieving Objects via Shelve. This definition is as follows:
from dataclasses import dataclass, field, asdict@dataclassclass Blog: title: str underline: str = field(init=False) # Part of the persistence, not essential to the class. _id: str = field(default="", init=False, compare=False) def __post_init__(self) -> None: self.underline = "=" * len(self.title)
This dataclass provides the essential title attribute for a blog. It has an optional attribute with the internal database ID assigned to ...
Read now
Unlock full access