未提供项目说明
print-dict的Python项目详细描述
打印dict
动机
显然,打印带有类和函数等值的嵌套python字典(在这里您不能使用json.dumps
)是很好的
不像你想的那么简单。在
参见:https://stackoverflow.com/questions/3229419/how-to-pretty-print-nested-dictionaries
这个图书馆试图让它变得简单一点。在
安装
$ pip install -U print-dict
使用
^{pr2}$例1
代码:
fromprint_dictimportpddict1={'key':'value'}pd(dict1)
输出:
{
'key': 'value'
}
例2
代码:
fromprint_dictimportpdclassObject1:passclassObject2:def__repr__(self):return"<Object2 info>"defcustom_method():passobject1=Object1()data={"one":"value-one","two":"value-two","three":"value-three","four":{'1':'1','2':'2','3':[1,2,3,4,5],'4':{'method':custom_method,'tuple':(1,2),'unicode':u'\u2713','ten':'value-ten','eleven':'value-eleven','3':[1,2,3,4]}},"object1":object1,"object2":Object2(),"class":Object1}pd(data)
输出:
{
'one': 'value-one',
'two': 'value-two',
'three': 'value-three',
'four': {
'1': '1',
'2': '2',
'3': [1, 2, 3, 4, 5],
'4': {
'method': <function custom_method at 0x7ff6ecd03e18>,
'tuple': (1, 2),
'unicode': '✓',
'ten': 'value-ten',
'eleven': 'value-eleven',
'3': [1, 2, 3, 4]
}
},
'object1': <__main__.Object1 object at 0x7ff6ecc588d0>,
'object2': <Object2 info>,
'class': <class '__main__.Object1'>
}
- 项目
标签: