Created
July 31, 2020 18:12
-
-
Save joelburton/d71e8bc5fac8c912fdf2bcf488003824 to your computer and use it in GitHub Desktop.
For JS programmers who like to use obj.key = val
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class POJO(dict): | |
def __getattr__(self, attr): | |
return self[attr] | |
def __setattr__(self, attr, val): | |
try: | |
super().__getattr__(self, attr) | |
super().__setattr__(self, attr, val) | |
except AttributeError: | |
self[attr] = val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment