3 ms·
There are a bunch of options for getting user["email"] and user.email to do the same thing: 1. Write a class with custom __getitem__ and __getattr__ methods 2
by simonw 3y ago
There are a bunch of options for getting user["email"] and user.email to do the same thing:
1. Write a class with custom __getitem__ and __getattr__ methods
2. Use a template system like Django or Jinja that implements this in certain situations
3. Use a library like https://pypi.org/project/python-box/ https://pypi.org/project/python-box/