From d2f3f6cb475cd9e8e562b5f13c6e15186c69b809 Mon Sep 17 00:00:00 2001 From: Isaac Cook Date: Sun, 14 Jul 2013 17:08:26 -0500 Subject: [PATCH] Added prettyprint for dict modules --- q.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/q.py b/q.py index c81a371..f6498a2 100644 --- a/q.py +++ b/q.py @@ -56,7 +56,7 @@ class Q(object): __doc__ = __doc__ # from the module's __doc__ above - import ast, code, inspect, os, pydoc, sys, random, re, time + import ast, code, inspect, os, pydoc, sys, random, re, time, pprint # The debugging log will go to this file; temporary files will also have # this path as a prefix, followed by a random number. @@ -159,6 +159,10 @@ def safe_repr(self, value): # TODO: Use colour to distinguish '...' elision from actual '...' chars. # TODO: Show a nicer repr for SRE.Match objects. # TODO: Show a nicer repr for big multiline strings. + # Use pretty print for dictionaries + if isinstance(value, dict) or isinstance(value, list): + pp = self.pprint.PrettyPrinter(indent=0) + return pp.pformat(value) result = self.TEXT_REPR.repr(value) if isinstance(value, basestring) and len(value) > 80: # If the string is big, save it to a file for later examination.