Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将带有 UTF-8 字符串的字典写入文件。我看到另一个关于使用 pprint 打印 utf-8 字符串的线程,并尝试像这样修改那里看到的代码
MyPrettyPrinter().pprint(dict, stream=f)
但它不工作。我对 python 的类没有经验,所以我不知道在 pprint 库中重新定义什么。
它应该是:
MyPrettyPrinter(stream=f).pprint(d)