**data_printer** - data printer and dumper
Project description
NAME
data_printer - data printer and dumper
VERSION
0.0.6
SYNOPSIS
from data_printer import p, np
import sys
from colored import fore, back, style
class A:
def __init__(self, **kw):
for k, v in kw.items():
setattr(self, k, v)
data = A(abc="acc", a=A(x=dict(p=10, r=[20, (2, 0.01)])), s='Строка\n', b=b'binary\n', r=r'\n')
# add ref to themselwes:
data.a.x['r'].append(data)
# print colored structure to sys.stdout
p(data)
# print colored structure to file stream
p(data, file=sys.stderr)
# print uncolored structure to file stream
p(data, file=sys.stderr, color=False)
# serialize structure to string
s = np(data)
# serialize structure to string without indexes: [6] -> [0] 6
s = np(data, indexes=False)
# serialize structure to colored string (colors as escape sequences)
s = np(data, color=True)
# default color scheme
p(data, color=dict(
bool = fore.LIGHT_BLUE,
none = fore.LIGHT_BLUE,
int = fore.LIGHT_YELLOW,
float = fore.LIGHT_YELLOW,
str = fore.LIGHT_GREEN,
bytes = fore.LIGHT_MAGENTA,
object = fore.LIGHT_RED,
any = fore.LIGHT_GRAY,
key = fore.LIGHT_CYAN,
ref = fore.RED,
punct = fore.WHITE,
))
# replace two colors
s = np(data, color=dict(
bool = fore.LIGHT_RED,
none = fore.LIGHT_YELLOW,
))
# print in perl-style (python - default) and without "[0] 7" in list "[7]".
p(data, sep="perl", indexes=False)
# print in node-style
p(data, sep="node")
# self-style
p(data, sep=dict(
kword=True,
oword=True,
kw=" => ",
kv=" => ",
object_open="bless {",
object_close="}, %n",
dict_open="{",
dict_close="}",
list_open="[",
list_close="]",
tuple_open="[",
tuple_close="]",
str='"%s"',
bytes='do { use bytes; "%s" }',
none="undef",
true="1",
false="0"
))
# self-style with two and lambda on bytes
p(data, sep=dict(
str='"%s"',
bytes=lambda s: "".join(['Buffer.from(", ', ", ".join(["0x%X" % ch for ch in s]) ,')']),
))
# print without newline on the end
p(data, end="")
DESCRIPTION
Data recursive printer. Serialize any python3 data to string or print in console or file.
Is colorised output.
Data printer check many references to one structure.
INSTALL
$ pip install data-printer
REQUIREMENTS
- colored
AUTHOR
Kosmina O. Yaroslav dart@cpan.org
LICENSE
MIT License
Copyright (c) 2020 Kosmina O. Yaroslav
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
data-printer-0.0.6.tar.gz
(6.1 kB
view hashes)
Built Distribution
Close
Hashes for data_printer-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f1aa849c54295254682116a48223f1ce1ace6c107c41e9556fe2cc85b3669bb |
|
MD5 | f6ef8594ecd25d42fe120cacb1327a14 |
|
BLAKE2b-256 | 6fec04a01bf6f1924c05f7ed62c007ae3f6e7e0c1265b7be3ddd3b157c1c28d2 |