file.py 文件源码

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

项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码
def safe_write(self, text):
        import os.path
        if not os.path.exists(self.filepath): # if the file does not exist, then can write
            try:
                with open(self.filepath, 'wt') as writer:
                    writer.write(text)
                return True
            except UnicodeEncodeError as ue:
                self.write_utf8(text)
                return True
            except Exception as e:
                if DEBUG_FLAG:
                    sys.stderr.write("Naked Framework Error: Unable to write to requested file with the safe_write() method (Naked.toolshed.file.py).")
                raise e
        else:
            return False # if file exists, do not write and return False

    #------------------------------------------------------------------------------
    # [ safe_write_bin method ]
    #   Binary data file writer that will NOT overwrite existing file at the requested filepath
    #   returns boolean indicator for success of write based upon test for existence of file (False = write failed because file exists)
    #------------------------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号