Skip to content

Commit 48f5147

Browse files
committed
added a more relevant example for pprint. Closes yasoob#145
1 parent 2cd38c3 commit 48f5147

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

one_liners.rst

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,59 @@ repl. Here is the relevant code:
2929
from pprint import pprint
3030
3131
my_dict = {'name': 'Yasoob', 'age': 'undefined', 'personality': 'awesome'}
32-
pprint(my_dict)
33-
34-
This is more effective on ``dict`` s. Moreover, if you want to pretty print
32+
print(dir(my_dict))
33+
# ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
34+
35+
pprint(dir(my_dict))
36+
# ['__add__',
37+
# '__class__',
38+
# '__contains__',
39+
# '__delattr__',
40+
# '__delitem__',
41+
# '__dir__',
42+
# '__doc__',
43+
# '__eq__',
44+
# '__format__',
45+
# '__ge__',
46+
# '__getattribute__',
47+
# '__getitem__',
48+
# '__gt__',
49+
# '__hash__',
50+
# '__iadd__',
51+
# '__imul__',
52+
# '__init__',
53+
# '__init_subclass__',
54+
# '__iter__',
55+
# '__le__',
56+
# '__len__',
57+
# '__lt__',
58+
# '__mul__',
59+
# '__ne__',
60+
# '__new__',
61+
# '__reduce__',
62+
# '__reduce_ex__',
63+
# '__repr__',
64+
# '__reversed__',
65+
# '__rmul__',
66+
# '__setattr__',
67+
# '__setitem__',
68+
# '__sizeof__',
69+
# '__str__',
70+
# '__subclasshook__',
71+
# 'append',
72+
# 'clear',
73+
# 'copy',
74+
# 'count',
75+
# 'extend',
76+
# 'index',
77+
# 'insert',
78+
# 'pop',
79+
# 'remove',
80+
# 'reverse',
81+
# 'sort']
82+
83+
84+
This is more effective on nested ``dict`` s. Moreover, if you want to pretty print
3585
json quickly from a file then you can simply do:
3686

3787
.. code:: python

0 commit comments

Comments
 (0)