Skip to main content

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.

Release files for printex 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for printex 0.0.7
File Size Uploaded
printex-0.0.7.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for printex 0.0.7
File Interpreter ABI Platform
printex-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / printex-0.0.7.tar.gz

Download URL printex-0.0.7.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9aba4564d57dffffbee0dce3f02f9624997cad8624f5c954667f420e37b18f4
BLAKE2b-256 checksum
How to use checksums
e73d05f51afc426f0ce581d5bb2f308aeb6fcfcd08f74ade28874d9a3370fcf7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / printex-0.0.7-py3-none-any.whl

Download URL printex-0.0.7-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
652e4b19ef757be18681a0670dc1fc79e55ba3e3dcdca1c3266b480ccd838e06
BLAKE2b-256 checksum
How to use checksums
7f912824e3cc18076e6de6a69a20ed83405f40717cd4741208a0d47a95e6d249
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page