Skip to content

Commit 7786ec1

Browse files
committed
Add some examples
1 parent 3e20e37 commit 7786ec1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

pep-9999.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,51 @@ Built-in :py:func:`print` takes a new optional argument, appended to the end of
9090
instantiation.
9191

9292

93+
Examples
94+
========
95+
96+
A custom ``__pprint__()`` method can be used to customize the representation of the object:
97+
98+
.. _code-block:
99+
100+
>>> class Custom:
101+
... def __str__(self): return 'my str'
102+
... def __repr__(self): return 'my repr'
103+
... def __pprint__(self, context, maxlevels, level): return 'my pprint'
104+
105+
>>> pprint.pp(Custom())
106+
my pprint
107+
108+
Using the ``pretty`` argument to ``print()``:
109+
110+
.. _code-block:
111+
112+
>>> import os
113+
>>> print(os.pathconf_names)
114+
{'PC_ASYNC_IO': 17, 'PC_CHOWN_RESTRICTED': 7, 'PC_FILESIZEBITS': 18, 'PC_LINK_MAX': 1, 'PC_MAX_CANON': 2, 'PC_MAX_INPUT': 3, 'PC_NAME_MAX': 4, 'PC_NO_TRUNC': 8, 'PC_PATH_MAX': 5, 'PC_PIPE_BUF': 6, 'PC_PRIO_IO': 19, 'PC_SYNC_IO': 25, 'PC_VDISABLE': 9, 'PC_MIN_HOLE_SIZE': 27, 'PC_ALLOC_SIZE_MIN': 16, 'PC_REC_INCR_XFER_SIZE': 20, 'PC_REC_MAX_XFER_SIZE': 21, 'PC_REC_MIN_XFER_SIZE': 22, 'PC_REC_XFER_ALIGN': 23, 'PC_SYMLINK_MAX': 24}
115+
>>> print(os.pathconf_names, pretty=True)
116+
{'PC_ALLOC_SIZE_MIN': 16,
117+
'PC_ASYNC_IO': 17,
118+
'PC_CHOWN_RESTRICTED': 7,
119+
'PC_FILESIZEBITS': 18,
120+
'PC_LINK_MAX': 1,
121+
'PC_MAX_CANON': 2,
122+
'PC_MAX_INPUT': 3,
123+
'PC_MIN_HOLE_SIZE': 27,
124+
'PC_NAME_MAX': 4,
125+
'PC_NO_TRUNC': 8,
126+
'PC_PATH_MAX': 5,
127+
'PC_PIPE_BUF': 6,
128+
'PC_PRIO_IO': 19,
129+
'PC_REC_INCR_XFER_SIZE': 20,
130+
'PC_REC_MAX_XFER_SIZE': 21,
131+
'PC_REC_MIN_XFER_SIZE': 22,
132+
'PC_REC_XFER_ALIGN': 23,
133+
'PC_SYMLINK_MAX': 24,
134+
'PC_SYNC_IO': 25,
135+
'PC_VDISABLE': 9}
136+
137+
93138
Backwards Compatibility
94139
=======================
95140

0 commit comments

Comments
 (0)