Package: printex
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 withpprint; 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.Installationpip3 install printexThis module is on piplinkTest programimport 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 programgraph:  <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>
      ]
    }
  ]
}APIclass pprintex.PrettyPrint( indentation_level = 0, stream = None )constructs a pretty printer object. The amount of indentation added for each recursive level is specified byindentation_levelpprintex.dprint( *args, sep=' ', end='\n', file=sys.stdout, flush=False)function is a replacement for built inprint, all arguments other than strings are pretty printed.class pprintex.PrettyPrintCfgconfiguration object for the pretty printer. has the following static members.indent_stringdefault value ' '; for each indentation level displays this string, can swap this to do tabs insteadspace_per_indentation_level- default value 2, each indentation level shows this number of indent_string instancesuse_repr_for_objects- default False, if set to true: don't display fields for an object, use repr insteadhow_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 printedobj.