June 2017
Beginner to intermediate
274 pages
6h 49m
English
Modifying class attributes is straightforward; we just use the built-in getattr, setattr, and delattr functions, as shown in the following code example:

In the preceding example, we see a simple class decorator that makes the attributes of the decorated class readable through the [] syntax; at the same time, it makes sure the class doesn't allow you to set or delete values through the [] syntax. While rewriting classes via decorators can be a powerful technique, it's not a complicated or surprising task, so there's nothing much to say about it.
We can also wrap up classes in their entirety. One common use of this ...
Read now
Unlock full access