Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itdxer/superdict
SuperDict - it's like dict, but better
https://github.com/itdxer/superdict
Last synced: 19 days ago
JSON representation
SuperDict - it's like dict, but better
- Host: GitHub
- URL: https://github.com/itdxer/superdict
- Owner: itdxer
- License: mit
- Created: 2015-01-27T23:41:54.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-28T14:34:41.000Z (almost 10 years ago)
- Last Synced: 2024-10-07T23:36:37.573Z (about 1 month ago)
- Language: Python
- Size: 152 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SuperDict
SuperDict - it's like dict, but better.
You don't change you dictionary to something new, you just make it better.
Module contains only 15 rows of code and valid by PEP8.
## Installation
```bash
$ pip install superdict
```## Usage
```python
>>> from superdict import SuperDict
>>>
>>> data = SuperDict()
>>>
>>> data.so.how.it = 'works'
>>> data
{'so': {'how': {'it': 'works'}}}
>>> data.so
{'how': {'it': 'works'}}
>>>
>>> data.test.me.please = 42
>>> data
{'test': {'me': {'please': 42}}, 'so': {'how': {'it': 'works'}}}
>>>
>>> del data.test.me
>>> data
{'test': {}, 'so': {'how': {'it': 'works'}}}
>>>
>>> data['so']['how']
{'it': 'works'}
>>>
>>> default_data = SuperDict({'default': {'x': 'y'}})
>>> default_data
{'default': {'x': 'y'}}
>>> default_data.default.x
'y'
>>>
>>> default_data = SuperDict({'default': SuperDict({'x': 'y'})})
>>> default_data
{'default': {'x': 'y'}}
>>> default_data.default.x
'y'
>>>
>>> real_dict = SuperDict({'is_success': True})
>>> copied_dict = real_dict.copy()
>>> copied_dict.is_success
True
```In another cases this class works like a dict.
```python
>>> default_data['unknown-key']
Traceback (most recent call last):
File "", line 1, in
KeyError: 'unknown-key'
>>>
>>> default_data['set'] = 'correct'
>>> default_data['new-set']['value'] = 'wrong'
Traceback (most recent call last):
File "", line 1, in
KeyError: 'new-set'
```