【问题标题】:PrettyPrinter - Print output on separate lines from the start and end bracketPrettyPrinter - 在开始和结束括号的不同行上打印输出
【发布时间】:2018-05-16 06:37:03
【问题描述】:

使用类似的东西:

pp = pprint.PrettyPrinter(indent=4, width=...).pprint

pp(my_list)的当前输出:

[   1,
    2,
    3]

期望的输出:

[
    1,
    2,
    3
]

如何做到这一点?

【问题讨论】:

    标签: python pretty-print


    【解决方案1】:

    使用 json 模块

    例如:

    import json
    my_list = [1,2,3]
    print(json.dumps(my_list, indent=4))
    

    输出:

    [
        1, 
        2, 
        3
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2019-04-28
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多