【发布时间】: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
使用类似的东西:
pp = pprint.PrettyPrinter(indent=4, width=...).pprint
pp(my_list)的当前输出:
[ 1,
2,
3]
期望的输出:
[
1,
2,
3
]
如何做到这一点?
【问题讨论】:
标签: python pretty-print
使用 json 模块。
例如:
import json
my_list = [1,2,3]
print(json.dumps(my_list, indent=4))
输出:
[
1,
2,
3
]
【讨论】: