print-dict
Motivation
Apparently, pretty-printing nested python dictionaries with values such as classes and functions (where you can't use json.dumps) is
not as straightforward as you would think.
See: https://stackoverflow.com/questions/3229419/how-to-pretty-print-nested-dictionaries
This library tries to make it a little bit easier.
Install or Upgrade
$ pip install -U print-dict
Usage
from print_dict import pd
pd({'key': 'value'})
# ------------------------
# Output:
# {
# 'key': 'value'
# }
# ------------------------
# Or
from print_dict import print_dict
print_dict({'key': 'value'})
# Get the string without printing
from print_dict import format_dict
string = format_dict({'key': 'value'})
Example 1
Code:
from print_dict import pd
dict1 = {
'key': 'value'
}
pd(dict1)
Output:
{
'key': 'value'
}
Example 2
Code:
from print_dict import pd
class Object1:
pass
class Object2:
def __repr__(self):
return "<Object2 info>"
def custom_method():
pass
object1 = Object1()
data = {
"one": "value-one",
"two": "value-two",
"three": "value-three",
"four": {
'1': '1', '2': '2', '3': [1, 2, 3, 4, 5], '4': {
'method': custom_method,
'tuple': (1, 2),
'unicode': u'\u2713',
'ten': 'value-ten',
'eleven': 'value-eleven',
'3': [1, 2, 3, 4]
}
},
"object1": object1,
"object2": Object2(),
"class": Object1
}
pd(data)
Output:
{
'one': 'value-one',
'two': 'value-two',
'three': 'value-three',
'four': {
'1': '1',
'2': '2',
'3': [1, 2, 3, 4, 5],
'4': {
'method': <function custom_method at 0x7ff6ecd03e18>,
'tuple': (1, 2),
'unicode': '✓',
'ten': 'value-ten',
'eleven': 'value-eleven',
'3': [1, 2, 3, 4]
}
},
'object1': <__main__.Object1 object at 0x7ff6ecc588d0>,
'object2': <Object2 info>,
'class': <class '__main__.Object1'>
}
Metadata
Release files for print-dict 0.1.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| print-dict-0.1.19.tar.gz | 8.5 kB | Without provenance | Details for print-dict-0.1.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| print_dict-0.1.19-py3-none-any.whl | Python 3 | none | any | Details for print_dict-0.1.19-py3-none-any.whl |
Total release size: 16.8 kB
Release files / print-dict-0.1.19.tar.gz
| Download URL | print-dict-0.1.19.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dff9bcd6279fe526bb7b13b392a373d88ed9d7647c2985b2457c475d7730d1d
|
|
BLAKE2b-256 checksum How to use checksums |
6ab60f4192508ef670e39967f78885cdf138d89885bd87d6edec34fdfa9a4227
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.6.10 Linux/5.4.0-66-generic
|
Release files / print_dict-0.1.19-py3-none-any.whl
| Download URL | print_dict-0.1.19-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b5c88df1f436c31c07c7a55e68ec6ac88a0554a0b793438e8b97eb1429cd4fc
|
|
BLAKE2b-256 checksum How to use checksums |
9f9f42bb270e27224389985ec8b1772c042cf03892b0c4a3cfba927befbd16e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.6.10 Linux/5.4.0-66-generic
|
Security for print-dict 0.1.19
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.