Skip to main content

similar to pprint, but shows all object field values.

Project description

printex - module for pretty printing of objects.

This library is a pretty printer of python objects. A pretty printer shows the structure of an object. If the argument is a collection, then it displays the structure of each element. This module has some similarities with pprint; however this is a new implementation. This module also shows the field values for an argument object; if the field values are themself objects, then their structure is also shows, recursively. To me that makes much more sense than what pprint is doing.

This library works with python3.

Installation

pip3 install printex

This module is on pip link

Test program

import pprintex

class Node:
    def __init__(self, name):
        self.name = name

class GraphNode(Node):
    def __init__(self, node_name):
        super(GraphNode, self).__init__(node_name)
        self.links = []

    def add_link(self, node):
        self.links.append(node)

root = GraphNode("root")
ch = GraphNode("node1")
root.add_link(ch)
ch2 = GraphNode("node2")
root.add_link(ch2)
ch = GraphNode("node3")
root.add_link(ch)
ch.add_link(root)

next_ch = GraphNode("node1.1")
ch2.add_link(next_ch)

next_ch = GraphNode("node2.1")
ch2.add_link(next_ch)

ch2.add_link(root)



pprintex.dprint("graph: ", root)

Output of test program

graph:  <class '__main__.GraphNode'> at 0x7fa2edb18cd0 fields: {
  'name' : 'root',
  'links' : [
    <class '__main__.GraphNode'> at 0x7fa2edb18bb0 fields: {
      'name' : 'node1',
      'links' : [
      ]
    },
    <class '__main__.GraphNode'> at 0x7fa2edb18a00 fields: {
      'name' : 'node2',
      'links' : [
        <class '__main__.GraphNode'> at 0x7fa2edb18910 fields: {
          'name' : 'node1.1',
          'links' : [
          ]
        },
        <class '__main__.GraphNode'> at 0x7fa2edb18730 fields: {
          'name' : 'node2.1',
          'links' : [
          ]
        },
        <Recursion on <class '__main__.GraphNode'> with id=0x7fa2edb18cd0>
      ]
    },
    <class '__main__.GraphNode'> at 0x7fa2edb18ac0 fields: {
      'name' : 'node3',
      'links' : [
        <Recursion on <class '__main__.GraphNode'> with id=0x7fa2edb18cd0>
      ]
    }
  ]
}

API

  • class pprintex.PrettyPrint( indentation_level = 0, stream = None )

    • constructs a pretty printer object. The amount of indentation added for each recursive level is specified by indentation_level
  • pprintex.dprint( *args, sep=' ', end='\n', file=sys.stdout, flush=False)

    • function is a replacement for built in print, all arguments other than strings are pretty printed.
  • class pprintex.PrettyPrintCfg

    • configuration object for the pretty printer. has the following static members.
      • indent_string default value ' '; for each indentation level displays this string, can swap this to do tabs instead
      • space_per_indentation_level - default value 2, each indentation level shows this number of indent_string instances
      • use_repr_for_objects - default False, if set to true: don't display fields for an object, use repr instead
      • how_nesting_prefix - for each line: show the nesting level.
      • force_repr - default: empty; force repr for this set of types
      • _dispatch - internal: dispatch for formatting function per type.
  • pprintex.pformat(obj, indentation_level=0)

    • return string that stands for pretty printed obj.

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

printex-0.0.7.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

printex-0.0.7-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file printex-0.0.7.tar.gz.

File metadata

  • Download URL: printex-0.0.7.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for printex-0.0.7.tar.gz
Algorithm Hash digest
SHA256 e9aba4564d57dffffbee0dce3f02f9624997cad8624f5c954667f420e37b18f4
MD5 d1e6655c655ca04cbacff60277e379ad
BLAKE2b-256 e73d05f51afc426f0ce581d5bb2f308aeb6fcfcd08f74ade28874d9a3370fcf7

See more details on using hashes here.

File details

Details for the file printex-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: printex-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for printex-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 652e4b19ef757be18681a0670dc1fc79e55ba3e3dcdca1c3266b480ccd838e06
MD5 dd8f6d3f8774dc3b42ccbefa99fa9300
BLAKE2b-256 7f912824e3cc18076e6de6a69a20ed83405f40717cd4741208a0d47a95e6d249

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page