genpy.py 文件源码

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

项目:pupy 作者: ru-faraon 项目源码 文件源码
def open_writer(self, filename, encoding="mbcs"):
    # A place to put code to open a file with the appropriate encoding.
    # Does *not* set self.file - just opens and returns a file.
    # Actually *deletes* the filename asked for and returns a handle to a
    # temp file - finish_writer then puts everything back in place.  This
    # is so errors don't leave a 1/2 generated file around causing bizarre
    # errors later.
    # Could be a classmethod one day...
    try:
      os.unlink(filename)
    except os.error:
      pass
    filename = filename + ".temp"
    if sys.version_info > (3,0):
      ret = open(filename, "wt", encoding=encoding)
    else:
      import codecs # not available in py3k.
      ret = codecs.open(filename, "w", encoding)
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号