jsondumpselfcmd_dict opencmd_path w如何令selfcmd_dict每个元素占一行
您可以在使用json.dump()函数时,指定参数indent=1来实现每个元素占一行,示例如下:
import json
class MyClass:
def save_cmd_dict(self, cmd_path):
with open(cmd_path, "w") as f:
json.dump(self.cmd_dict, f, indent=1)
在上面的示例中,json.dump()函数的第三个参数indent被设置为1,这样每个元素就会占一行。
原文地址: https://www.cveoy.top/t/topic/fFkc 著作权归作者所有。请勿转载和采集!