Skip to Content
Clean Code in Python
book

Clean Code in Python

by Mariano Anaya
August 2018
Intermediate to advanced
332 pages
9h 12m
English
Packt Publishing
Content preview from Clean Code in Python

__set__(self, instance, value)

This method is called when we try to assign something to a descriptor. It is activated with statements such as the following, in which a descriptor is an object that implements __set__ (). The instance parameter, in this case, would be client, and the value would be the "value" string:

client.descriptor = "value"

If client.descriptor doesn't implement __set__(), then "value" will override the descriptor entirely.

Be careful when assigning a value to an attribute that is a descriptor. Make sure it implements the __set__ method, and that we are not causing an undesired side effect.

By default, the most common use of this method is just to store data in an object. Nevertheless, we have seen how powerful descriptors ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Clean Code in Python - Second Edition

Clean Code in Python - Second Edition

Mariano Anaya
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781788835831Supplemental Content