Python library for easy-to-read conversion of a dictionary to a string and pretty printing.
Project description
Dictppr
A package that allows easy-to-read conversion of a dictionary to a string and pretty printing.
Features
- Convert dictionary to string
- Convert dictionary to dictionary of string
- Pretty print dictionary
Installation
Download the latest version from PyPi
python -m pip install dictppr
Developers should also install tests dependencies
pip install -r requirements_dev.txt
Testing
Perform the tests with pytest
(or Tox
)
python -m pytest tests
To check test coverage
coverage report -m
Current coverage:
Name | Stmts | Miss | Cover |
---|---|---|---|
dictppr\__init__.py | 3 | 0 | 100% |
dictppr\dictppr.py | 68 | 1 | 99% |
Usage
First, you need to import the package:
import dictppr
Now, to get string from dictionary:
string = dictppr.get({...})
..or to get dictionary of strings:
dictionary = dictppr.convert({...})
..or you just want to print it:
dictppr.pprint({...})
If you need to check version of dictppr, use:
print(dictppr.__version__)
Examples
You have dictionary like that:
sample = {
"key_1": "val_1",
"key_2": {
"key_3": "val_3",
"key_4": "val_4"
}
}
You will get this string with the get
function:
string = "key_1:val_1, key_2:key_3:val_3, key_4:val_4"
You will get this dictionary with the convert
function:
dictionary = {"key_1": "val_1", "key_2": "key_3:val_3, key_4:val_4"}
You will get this stdout with the pprint
function:
key_1 => val_1
key_2 => key_3:val_3, key_4:val_4
Contributing
Pull requests are welcome!
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.