Skip to main content

**data_printer** - data printer and dumper

Project description

NAME

data_printer - data printer and dumper

VERSION

0.0.4

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,
    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.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

data_printer-0.0.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file data-printer-0.0.4.tar.gz.

File metadata

  • Download URL: data-printer-0.0.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for data-printer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 bc692773ab24a5aa7b0b92645e1c70185d8f5cb1711569d2a58b84f830c70d1f
MD5 2f3e07c30439ba9799a4839e084c6b35
BLAKE2b-256 2871c59d5e3308c934a9d4684ecf103ef57cb214d24f1260cd2662fc87bda023

See more details on using hashes here.

File details

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

File metadata

  • Download URL: data_printer-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for data_printer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 025484a982be040d62030c90569c8d931de81b31dc1b1f14c62be5d3ddbae498
MD5 c395c1f1392055554e39534697fd6054
BLAKE2b-256 def588fa7dbd816de97cc988954b8fb279b91c868b02dc130798343d7c713c5d

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