Python中使用不同编码读写txt文件详解

这篇文章主要介绍了Python中使用不同编码读写txt文件详解,本文给出不同编码下的读写文件代码方法,需要的朋友可以参考下

复制代码 代码如下:

import os
import codecs
filenames=os.listdir(os.getcwd())

out=file("name.txt","w")
for filename in filenames:
 out.write(filename.decode("gb2312").encode("utf-8"))
out.close()

以上就是Python中使用不同编码读写txt文件详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python