jsondumpselfcmd_dict opencmd_path w如何缩进2格
可以通过在json.dump()函数中传递indent参数来设置缩进的空格数,如下所示:
import json
# 将self.cmd_dict字典数据写入json文件并缩进2格
with open(cmd_path, "w") as f:
json.dump(self.cmd_dict, f, indent=2)
在上述代码中,将self.cmd_dict字典数据写入json文件时,通过indent参数设置缩进的空格数为2。
原文地址: https://www.cveoy.top/t/topic/fFhQ 著作权归作者所有。请勿转载和采集!