美文网首页
Python UTF-8 编码格式读写文件

Python UTF-8 编码格式读写文件

作者: 旋光 | 来源:发表于2016-01-28 16:06 被阅读0次

    指定UTF-8编码格式读入

    import codecs
        with codecs.open(fileName, encoding = "utf-8") as fin:
        for line in fin:
            ...
    
    

    指定UTF-8编码格式写入

    import codecs
        fout = codecs.open(fileName, "w+", "utf-8")
        fout.write("<node id=\"%d\" label=\"%s\">\n" % (i, str))
        ...
        fout.close()
    

    相关文章

      网友评论

          本文标题:Python UTF-8 编码格式读写文件

          本文链接:https://www.haomeiwen.com/subject/jekjkttx.html