def __call__(self, object, stream=None, indent=1, width=80, depth=None): """copy from `pprint.pprint`""" from pprint import PrettyPrinter import re printer = PrettyPrinter(stream=stream, indent=indent, width=width, depth=depth) stream = printer._stream color_stream = type('',(),{})() printer._stream = color_stream colored = colorform(self.values).format #color_stream.write = lambda s: stream.write(colored(s)) def write(s, patt=re.compile(r'^(,?)(\n\ *)(.*)$')): m = patt.match(s) if m is not None: a, b, c = m.groups() stream.write((a and colored(a)) + b + (c and colored(c))) else: stream.write(colored(s)) color_stream.write = write printer.pprint(object)