python库查询
pprint库很好使用,它提供pprint()和pformat()两种费中好用的函数。
直接上手pip isntall pprint
会出现错误,所以要换一个源。
pip install pprint -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pprint()将输入的对象直接打印到控制台。
pprint.pprint(object, stream=None, indent=1, width=80, depth=None, *, compact=False, sort_dicts=True, underscore_numbers=False)
解释其中几个参数:
>>> import pprint
>>> company = {
... "Apple": {"founder": "Steven Jobs", "prodctions":["IPhone", "Mac"]},
... "MicroSoft":{"founder": "Bill Gates", "prodctions": ["Windows", "Office","Xbox"]},
... }
>>> pprint.pprint(company)
{'Apple': {'founder': 'Steven Jobs', 'prodctions': ['IPhone', 'Mac']},
'MicroSoft': {'founder': 'Bill Gates',
'prodctions': ['Windows', 'Office', 'Xbox']}}
>>> print(company)
{'Apple': {'founder': 'Steven Jobs', 'prodctions': ['IPhone', 'Mac']}, 'MicroSoft': {'founder': 'Bill Gates', 'prodctions': ['Windows', 'Office', 'Xbox']}}
>>>
未完待续