setattr is a Python built-in function used to set a named attribute on an object.
The function's schematics are as follows:
setattr(object:object, name:str, value:object) -> object
where object
is the object, name
is the named attribute, and value
is the value that name
will be set to. Below is an example:
>>> class Test:
... def __init__(self):
... self.attr = 1
...
>>> myTest = Test()
>>> myTest.attr
1
>>> setattr(myTest, 'attr', 2)
>>> myTest.attr
2
>>>