Next / Previous / Contents / TCC Help System / NM Tech homepage

14.18. setattr(): Set an attribute

This function is similar to Section 14.8, “getattr(): Retrieve an attribute of a given name”: it sets the value of some attribute whose name is A from an instance I to a new value V:

setattr(I, A, V)

Example:

>>> class C5:
...     def __init__(self, x):
...         self.x = x
... 
>>> c=C5(14)
>>> c.x
14
>>> setattr(c, 'x', 19)
>>> c.x
19