dataIO.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:youtube 作者: FishyFing 项目源码 文件源码
def save_json(self, filename, data):
        """Atomically saves json file"""
        rnd = randint(1000, 9999)
        path, ext = os.path.splitext(filename)
        tmp_file = "{}-{}.tmp".format(path, rnd)
        self._save_json(tmp_file, data)
        try:
            self._read_json(tmp_file)
        except json.decoder.JSONDecodeError:
            self.logger.exception("Attempted to write file {} but JSON "
                                  "integrity check on tmp file has failed. "
                                  "The original file is unaltered."
                                  "".format(filename))
            return False
        os.replace(tmp_file, filename)
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号