Skip to main content

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

  1. some_dictionary = DictShaper(some_dictionary)
  2. 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

  1. some_dictionary = DictShaper(some_dictionary)
  2. some_dictionary.shape(name='shaped_dict', write_to=True)
  3. shaped_dict = {
  4.     'Level-1 el-1': [0, 1, 2, 3, 4],
  5.     'Level-1 el-2': {
  6.         'Level-2 el-1': 1,
  7.         'Level-2 el-2': 2,
  8.     },
  9.     'Level-1 el-3': 'Some string',
  10.     'Level-1 el-4': ('Tuple', 1, ['a', 'b']),
  11.     'Level-1 el-5': {
  12.         'Level-2 el-3': {
  13.             'Level-3 el-1': 'https://some-site.com/page1?par=120&another=500',
  14.             'Level-3 el-2': (9, 125, 87),
  15.             'Level-3 el-3': 'Very very very very very very very very very very long string.',
  16.         },
  17.         'Level-2 el-4': 2,
  18.     },
  19.     'Level-1 el-6': {},
  20.     'Level-1 el-7': 'The end of the dictionary!',
  21. } 25.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictshaper-0.0.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictshaper-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file dictshaper-0.0.4.tar.gz.

File metadata

  • Download URL: dictshaper-0.0.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.9

File hashes

Hashes for dictshaper-0.0.4.tar.gz
Algorithm Hash digest
SHA256 512f5e66537999b3677e6a54a3107bd54e36bbd5665085a76a452d7d0ae53936
MD5 a7763f7bade77d98ae2dcec780b99aff
BLAKE2b-256 ddf8fecb18b7cabbe2a468385b3811472644c22a4daecce84c44e94c9ea5f88d

See more details on using hashes here.

File details

Details for the file dictshaper-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: dictshaper-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.9

File hashes

Hashes for dictshaper-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f07998d45690edef6387636a3f5d4e296935d442d6a89a53b775572573ad4e17
MD5 9d32559ea701d481083fd012efd3cb0b
BLAKE2b-256 a0c04aca934ae8de003694bd4536b691743453951968cb0efafe73354f5e3666

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page