We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e09a25b commit e05721cCopy full SHA for e05721c
python-stdlib/pprint/pprint.py
@@ -1,6 +1,30 @@
1
-def pformat(obj):
2
- return repr(obj)
3
4
5
-def pprint(obj):
6
- print(repr(obj))
+
+def _pprint(obj, stream=None, indent=0):
+ if stream is None:
+ import sys
7
+ stream = sys.stdout
8
9
+ if isinstance(obj, dict):
10
+ stream.write("{\n")
11
+ for k, v in obj.items():
12
+ stream.write(" "*indent)
13
+ _pprint(k, stream, indent+1)
14
+ stream.write(": ")
15
+ _pprint(v, stream, indent+1)
16
+ stream.write(",\n")
17
+ stream.write(" "*indent+"}")
18
+ else:
19
+ print(repr(obj), file=stream, end="")
20
21
22
+def pformat(obj):
23
+ import io
24
+ buf = io.StringIO()
25
+ _pprint(obj, buf)
26
+ return buf.getvalue()
27
28
+def pprint(obj, stream=None):
29
+ _pprint(obj, stream)
30
+ print(file=stream)
0 commit comments