Search notes:

Python: setattr

It is possible to add dynamic attributes to an object just by assigning a value to a property name.
class CLS: pass

obj = CLS()

obj.attr_one = 42
obj.attr_two ='hello World'

print(obj.attr_one, obj.attr_two)
Github repository about-Python, path: /built-in/functions/setattr/dynamically-add-attributes.py
In the above script, only attribute-names can be used that are known at the time that the script was written. In order to an attribute with an arbitrary name that is stored in a variable, setattr() can be used:
class CLS: pass

obj = CLS()

setattr(obj, 'attr_one',  42          )
setattr(obj, 'attr_two', 'Hello world')

print(obj.attr_one, obj.attr_two)
Github repository about-Python, path: /built-in/functions/setattr/dynamic-names.py

See also

__setattr__
Python: Built in functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199202, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/built-in/functions/setattr(60): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78