从ANSI转换为UTF-8

Kar*_*ala 6 python r notepad++


我有大约600,000个文件编码ANSI,我想将它们转换为UTF-8.我能做到这一点单独的NOTEPAD++,但我不能这样做,600,000 files.Can我这样做的R还是Python

我找到了这个链接,但Python脚本没有运行: notepad ++将ansi编码文件转换为utf-8

小智 6

为什么不读取文件并将其写为UTF-8?你可以用Python做到这一点.

#to support encodings
import codecs

#read input file
with codecs.open(path, 'r', encoding = 'utf8') as file:
  lines = file.read()

#write output file
with codecs.open(path, 'w', encoding = 'utf8') as file:
  file.write(lines)
Run Code Online (Sandbox Code Playgroud)

  • 不会读取utf-8一个不同的代码页松散一些字符?(虽然在写入另一个代码页之前你必须阅读正确的代码页)? (5认同)