Skip to content Skip to main navigation Skip to footer

Python中使用不同编码读写文件的详细介绍

下面的内容主要介绍了Python中使用不同编码读写文件,欢迎大家参考:

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中使用不同编码读写文件就是这样,欢迎大家参考。。。。

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.