Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from pprint import pprint
- class NamedDict(dict):
- def __getattr__(self, attr):
- return self.get(attr)
- def __setattr__(self, attr, value):
- self.update({attr: value})
- ndict = NamedDict()
- ndict.x = 10
- ndict.y = 25
- ndict.val = random.randint(0, 1000)
- print('Dicts content:')
- pprint(ndict)
- print('\n\nDir:')
- pprint(dir(ndict))
- #ndict.5 = 22 wont work
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement