Form a dictionary to a convenient shape for output or writing to a file.
Project description
DictShaper
The module for convenient viewing of dictionary with the all necessary indents.
This module extends the standard dict
class, so you can
use all its properties and methods. Over all of this DictShaper
adds the new method shape()
. You can also give a name for your
dictionary by the name=
param.
your_dictionary.shape(name='any_name')
You can also add a path to a file for writing the dictionary there,
using the write_to=
param. It will be writing in a convenient view,
like in an example below.
your_dictionary.shape(name='any_name', write_to='any_path')
If you set as a value 1
or True
in write_to=
param then the
dictionary will be writing to the end of a current file.
EXAMPLES
We will work with the dictionary below called 'some dictionary'.
some_dictionary = {'Level-1 el-1': [0, 1, 2, 3, 4], 'Level-1 el-2': {'Level-2 el-1': 1, 'Level-2 el-2': 2}, 'Level-1 el-3': 'Some string', 'Level-1 el-4': ('Tuple', 1, ['a', 'b']), 'Level-1 el-5': {'Level-2 el-3': {'Level-3 el-1': 'https://some-site.com/page1?par=120&another=500', 'Level-3 el-2': (9, 125, 87), 'Level-3 el-3': 'Very very very very very very very very very very long string.'}, 'Level-2 el-4': 2}, 'Level-1 el-6': {}, 'Level-1 el-7': 'The end of the dictionary!'}
First you need to import this module with the following command
from dictshaper.shaper import DictShaper
For outputting the dict without a name to a console
Enter following commands
some_dictionary = DictShaper(some_dictionary)
print(some_dictionary.shape())
- You also can add the 'name=' param
Output
{
'Level-1 el-1': [0, 1, 2, 3, 4],
'Level-1 el-2': {
'Level-2 el-1': 1,
'Level-2 el-2': 2,
},
'Level-1 el-3': 'Some string',
'Level-1 el-4': ('Tuple', 1, ['a', 'b']),
'Level-1 el-5': {
'Level-2 el-3': {
'Level-3 el-1': 'https://some-site.com/page1?par=120&another=500',
'Level-3 el-2': (9, 125, 87),
'Level-3 el-3': 'Very very very very very very very very very very long string.',
},
'Level-2 el-4': 2,
},
'Level-1 el-6': {},
'Level-1 el-7': 'The end of the dictionary!',
}
For writing the dict with a name to a file
some_dictionary = DictShaper(some_dictionary)
some_dictionary.shape(name='shaped_dict', write_to=True)
shaped_dict = {
'Level-1 el-1': [0, 1, 2, 3, 4],
'Level-1 el-2': {
'Level-2 el-1': 1,
'Level-2 el-2': 2,
},
'Level-1 el-3': 'Some string',
'Level-1 el-4': ('Tuple', 1, ['a', 'b']),
'Level-1 el-5': {
'Level-2 el-3': {
'Level-3 el-1': 'https://some-site.com/page1?par=120&another=500',
'Level-3 el-2': (9, 125, 87),
'Level-3 el-3': 'Very very very very very very very very very very long string.',
},
'Level-2 el-4': 2,
},
'Level-1 el-6': {},
'Level-1 el-7': 'The end of the dictionary!',
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dictshaper-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f07998d45690edef6387636a3f5d4e296935d442d6a89a53b775572573ad4e17 |
|
MD5 | 9d32559ea701d481083fd012efd3cb0b |
|
BLAKE2b-256 | a0c04aca934ae8de003694bd4536b691743453951968cb0efafe73354f5e3666 |