Skip to Content
Python in a Nutshell
book

Python in a Nutshell

by Alex Martelli
March 2003
Intermediate to advanced
656 pages
39h 30m
English
O'Reilly Media, Inc.
Content preview from Python in a Nutshell

Name

__setattr__

Synopsis

__setattr__(self, name, value)

At every request to bind attribute x.y (typically, an assignment statement x.y = value), Python calls x .__setattr__('y',value ). Python always calls __setattr__ for any attribute binding on x; a major difference from __getattr__ (__setattr__ is closer to new-style classes’ __getattribute__ in this sense). To avoid recursion, when x .__setattr__ binds x’s attributes, it must modify x .__dict__ directly (e.g., by x .__dict__[ name ]= value), or better, for a new-style class, delegate (e.g., call super(C, x).__setattr__('y',value )). Python ignores the return value of __setattr__. If __setattr__ is absent, Python usually translates x.y = z into x .__dict__['y']= z.

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

Python in a Nutshell, 3rd Edition

Python in a Nutshell, 3rd Edition

Alex Martelli, Anna Ravenscroft, Steve Holden
Python in a Nutshell, 4th Edition

Python in a Nutshell, 4th Edition

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire
Data Wrangling with Python

Data Wrangling with Python

Jacqueline Kazil, Katharine Jarmul

Publisher Resources

ISBN: 0596001886Supplemental ContentCatalog PageErrata