summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2003-12-03 20:26:05 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2003-12-03 20:26:05 (GMT)
commitc8de4585a6e52e1186828dd929671d3a6c36db95 (patch)
treeb3e5ad74c31c3bb634828a121f7b7d9919fabdb3 /Lib
parent7a7ede54d4311d3bcb5000aeedeab8cc80391c70 (diff)
downloadcpython-c8de4585a6e52e1186828dd929671d3a6c36db95.zip
cpython-c8de4585a6e52e1186828dd929671d3a6c36db95.tar.gz
cpython-c8de4585a6e52e1186828dd929671d3a6c36db95.tar.bz2
Add parameters indent, width and depth to pprint.pprint() and pprint.pformat()
and pass them along to the PrettyPrinter constructor.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pprint.py9
-rw-r--r--Lib/test/test_pprint.py6
2 files changed, 11 insertions, 4 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py
index 19b9661..d938122 100644
--- a/Lib/pprint.py
+++ b/Lib/pprint.py
@@ -48,14 +48,15 @@ _len = len
_type = type
-def pprint(object, stream=None):
+def pprint(object, stream=None, indent=1, width=80, depth=None):
"""Pretty-print a Python object to a stream [default is sys.sydout]."""
- printer = PrettyPrinter(stream=stream)
+ printer = PrettyPrinter(
+ stream=stream, indent=indent, width=width, depth=depth)
printer.pprint(object)
-def pformat(object):
+def pformat(object, indent=1, width=80, depth=None):
"""Format a Python object into a pretty-printed representation."""
- return PrettyPrinter().pformat(object)
+ return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
def saferepr(object):
"""Version of repr() which can handle recursive data structures."""
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index d66b78a..a61bb66 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -154,6 +154,12 @@ class QueryTestCase(unittest.TestCase):
for type in [tuple, tuple2]:
self.assertEqual(pprint.pformat(type(o)), exp)
+ # indent parameter
+ o = range(100)
+ exp = '[ %s]' % ',\n '.join(map(str, o))
+ for type in [list, list2]:
+ self.assertEqual(pprint.pformat(type(o), indent=4), exp)
+
def test_subclassing(self):
o = {'names with spaces': 'should be presented using repr()',
'others.should.not.be': 'like.this'}