Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Classtionary(dict):
- """A Class, er, dictionary, um, attributes-as-keys thingy.
- >>> c = Classtionary(foo="bar")
- >>> d = dict(foo="bar")
- >>> c, d
- ({'foo': 'bar'}, {'foo': 'bar'})
- >>> c.fizz = "bang"
- >>> d.fizz = "bang"
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- AttributeError: 'dict' object has no attribute 'fizz'
- >>> d['fizz'] = "bang"
- >>> c['fizz']
- 'bang'
- >>> c.fizz
- 'bang'
- >>> d['fizz']
- 'bang'
- >>> d.fizz
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- AttributeError: 'dict' object has no attribute 'fizz'
- """
- def __init__(self, **kwargs):
- self.__dict__ = self
- self.update(kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement