__init__.py 文件源码

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

项目:otRebuilder 作者: Pal3love 项目源码 文件源码
def writeFileAtomically(text, path, encoding="utf-8"):
    """
    Write text into a file at path. Do this sort of atomically
    making it harder to cause corrupt files. This also checks to see
    if text matches the text that is already in the file at path.
    If so, the file is not rewritten so that the modification date
    is preserved. An encoding may be passed if needed.
    """
    if os.path.exists(path):
        with open(path, "r", encoding=encoding) as f:
            oldText = f.read()
        if text == oldText:
            return
        # if the text is empty, remove the existing file
        if not text:
            os.remove(path)
    if text:
        with open(path, "w", encoding=encoding) as f:
            f.write(text)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号