PrettyPrinter - 在开始和结束括号的不同行上打印输出

PrettyPrinter - Print output on separate lines from the start and end bracket

使用类似的东西:

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

pp(my_list)的当前输出:

[   1,
    2,
    3]

期望的输出:

[
    1,
    2,
    3
]

如何做到这一点?

使用 json 模块

例如:

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

输出:

[
    1, 
    2, 
    3
]