未提供项目说明

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'>
}


欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaGWT:何时使用Lazydemelement?   Java中跟踪消失线程的多线程处理   java Springboot未能配置数据源:“url”,但我没有使用数据库   java为按钮生成随机位置   math Java:包含二项式系数计算的表达式   java通过AsyncTask传递参数   从路径错误创建java文件   高流量网站的性能播放框架、Java、Apache、PostgreSQL、JPA和Hibernate   java将4D矢量转换为长矢量   arraylist Java循环在没有任何错误的情况下终止   java正在制作一个计算器应用程序,希望在第二个片段中更新历史,但无法完成   java将信息从IntentService发送到Activity   java如何在游戏中插入大量实体!工作   javascript如何在ScriptEngineforJava中从数学中获得准确的结果?