A pretty printer for SimpleNamespace
Project description
Pretty SimpleNamespace
Table of Contents
What is it?
- A stringifier and formatter for SimpleNamespace which attempts to make the data as readable as possible.
Why create it?
- I use SimpleNamespace often to hold state and needed a way to print it out for debugging purposes.
Simple usage
from pretty_simple_namespace import pprint
from types import SimpleNamespace as o
joe = o(
name={"first": "joe", "last": "schmo"},
age=30,
favoriteFoods=["apples", "steak"],
)
pprint(joe)
# prints
# {
# name: {
# first: 'joe'
# last: 'schmo'
# }
# age: 30
# favoriteFoods: [
# 'apples'
# 'steak'
# ]
# }
Features
- handles recursive structures by tracking and printing references nicely
- recurses into types
list,dictandSimpleNamespacefor now - has special-case printing for types
bool,str,callableandNone- booleans and None are printed lowercase
- strings are wrapped in single quotes
- callable appends
()e.g.myMethod(). Arguments aren't represented
- all other types are printed by wrapping it in
stre.g.str(userDefinedType)
Limitations
- multi-line strings look ugly
- doesn't have a way to recurse into structures other than what's listed above
Related projects
Api
format(something, indent=2) => str
- formats
somethingto a string as seen in Simple usage
pprint(something, indent=2) => None
- just prints the formated
something
wrapWith(*, indent) => Wrapped module
-
use this when you want to call
formatorpprintwith a different default indent value so you don't have to pass it manually all the time.e.g.
from pretty_simple_namespace import wrapWith pprint = wrapWith(indent=4).pprint pprint(o(tabbed4spaces=True)) # { # tabbed4spaces: true # }
Wrapped module
- just an instance of SimpleNamespace with two attributes
formatandpprint.
Test
#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py
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
pretty_simple_namespace-0.1.1.tar.gz
(914.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pretty_simple_namespace-0.1.1.tar.gz.
File metadata
- Download URL: pretty_simple_namespace-0.1.1.tar.gz
- Upload date:
- Size: 914.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7579dcb10091defe84d3702aa0680b8ccf4ee00f93e8b0bf85195a7b93aef4af
|
|
| MD5 |
efb4f8fc0f391588fad309f74f2e5c47
|
|
| BLAKE2b-256 |
1edf54830ecc0bc254b7a53e160f734fcad933a69c901c42cadaca71892c5369
|
File details
Details for the file pretty_simple_namespace-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pretty_simple_namespace-0.1.1-py3-none-any.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17cb165fa3a3e55605c6f3204bf077d62fc53a7005afe2de3cb9c4ed6c2718a5
|
|
| MD5 |
c3d1d72716c1debc3799b1070e8a56e9
|
|
| BLAKE2b-256 |
b28c461c20ac66fe60e912985ec578fe9cebad62033198e559482d6fc6311ba7
|