
Senior Software Engineer @alma_pay | ex Somfy Protect Myfox, @Makina_Corpus
- Tweets7.8K
- Following734
- Followers363
- Likes5.2K

ALT from types import SimpleNamespace data = {"name": "Alice", "age": 25, "occupation": "Designer"} # Converting the dictionary to a SimpleNamespace object person_data = SimpleNamespace(**data) # Accessing data using attribute-style access print(person_data.name) # Output: Alice print(person_data.age) # Output: 25
![>>> from collections import namedtuple >>> from datetime import date >>> Transaction = namedtuple('Transaction', 'giver points date') >>> tr = Transaction('tim', 5, date.today()) # or: Transaction(giver='tim', points=5, date=date.today()) >>> tr Transaction(giver='tim', points=5, date=datetime.date(2020, 11, 14)) >>> tr[0] 'tim' >>> tr.giver 'tim' >>> tr.points 5 >>> tr.points = 10 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: can't set attribute](https://pbs.twimg.com/media/F13i8QWX0AAxQ54.jpg?name=small&format=webp)
ALT >>> from collections import namedtuple >>> from datetime import date >>> Transaction = namedtuple('Transaction', 'giver points date') >>> tr = Transaction('tim', 5, date.today()) # or: Transaction(giver='tim', points=5, date=date.today()) >>> tr Transaction(giver='tim', points=5, date=datetime.date(2020, 11, 14)) >>> tr[0] 'tim' >>> tr.giver 'tim' >>> tr.points 5 >>> tr.points = 10 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: can't set attribute






























