June 2019
Beginner to intermediate
770 pages
19h 24m
English
We can define an object where attributes are computed eagerly — as soon as — possible after a value is set. An object such as this can optimize access by performing a computation once and leaving the result to be used multiple times.
This can be done with property setters. However, a class with a lot of property setters, each of which computes a number of attributes, can be rather complex-looking. In some cases, all of the derived value computations can be centralized.
The dataclasses module provides us with a class with an array of built-in features. One of these features is a __post_init__() method that we can use to derive values eagerly.
We'd like something that looks like ...
Read now
Unlock full access