Python 读入windows 的记事本内容 编码 类别(ANSI,utf-8,Unicode)

来源:互联网 发布:工信部网站域名查询 编辑:程序博客网 时间:2024/05/01 15:09

1.ANSI  

这里的 ANSI 指 ANSI code pages(注意复数),是整个非 Unicode 字符集的集合。

ANSI code pages 这个名字是微软的历史遗留问题,正式名称是 Windows code pages……

所以实际上是以当前系统的编码为准的,简体中文系统用的 code page 是 936(GBK 字符集),

所以Python中读入 记事本 .txt

f = open ( ' test.txt ' , ' r ' )

content = f . read()

dcontent = content . decode ( ' gbk ' ) 


2.utf-8

f = open ( ' test.txt ' , ' r ' )

content = f . read()

dcontent = content . decode ( ' utf-8 ' ) 



0 0