Python实现ANSI文件转UTF-8

ANSI编码的文件转为UTF-8编码的文件。

# ANSI文件转UTF-8
import codecs
import os

# 文件所在目录
file_path = "H:\Python\South.Park.S02.WEB-DL.chs"
files = os.listdir(file_path)

for file in files:
    file_name = file_path + '\\' + file
    f = codecs.open(file_name, 'r', 'ansi')
    ff = f.read()
    file_object = codecs.open(file_path + '\\' + file, 'w', 'utf-8')
    file_object.write(ff)

  

posted @ 2017-05-19 12:54  Hello_2018  阅读(19683)  评论(0编辑  收藏  举报