python - PrettyPrinter - 在开始和结束括号的不同行上打印输出
问题描述
使用类似的东西:
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
]
推荐阅读
- java - 使用 Junit 生成多个单元测试
- python - 在 python 2.7 中构建、安装和运行 yoink
- java - 空白最终变量
- python - Pandas 无法将 excel 数据读取为字符串
- spring-boot - 使用 kotlin 时 Spring Boot aop 建议未触发
- modelica - 在 JModelica 中未正确调用 c 函数
- bash - 连接第一列中匹配值的第二列行并生成文件
- intellij-idea - 将 IntelliJ 插件放在状态栏中
- java - 在请求目标中发现无效字符。上传文件时,有效字符在 RFC 7230 和 RFC 3986 中定义
- windows - 如何在 PostgreSQL 上进行转储?