with open('data.json', 'r') as f:
self.cfg = json.load(f)
上述代码段可以读取data.json,
问题是,如果data.json不存在,我该怎样处理?
我在Google搜了一下, 基本都是介绍with的, 无奈本人英文不是太好, 或许错过了些什么...
我的期望是:
如果data.json不存在,便创建并写入Json格式的默认参数。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
闭关修行中......