python - 在 Python 中解码 Mac OS 文本

标签 python macos

我正在编写一些代码来解析 RTF 文档,并且需要处理它们可以使用的各种代码页。 Python 附带了所有必要的 Windows 代码页的解码器,但我不确定如何处理 Mac 代码页:

# 77: "10000", # Mac Roman
# 78: "10001", # Mac Shift Jis
# 79: "10003", # Mac Hangul
# 80: "10008", # Mac GB2312
# 81: "10002", # Mac Big5
# 83: "10005", # Mac Hebrew
# 84: "10004", # Mac Arabic
# 85: "10006", # Mac Greek
# 86: "10081", # Mac Turkish
# 87: "10021", # Mac Thai
# 88: "10029", # Mac East Europe
# 89: "10007", # Mac Russian

Python 是否内置了对这些的支持?如果没有,是否有一个跨平台的纯 Python 库可以处理它们?

最佳答案

您可以使用 python 编解码器来处理名称为“mac-roman”、“mac-turkish”等的编解码器。

>>> 'foo'.decode('mac-turkish')
u'foo'

你必须通过他们的名字来引用他们,你在问题中得到的这些数字不会出现在源文件中。有关详细信息,请查看 $pylib/encodings/mac_*.py

关于python - 在 Python 中解码 Mac OS 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592925/

相关文章:

python - Python中如何使用VIPS进行逻辑运算和逻辑索引?

python - 将字典中的键与字符串列表进行比较并对值求和

python - undefined symbol : PyUnicodeUCS4_FromStringAndSize with tensorflow on heroku

python - 如何比较3列数据?

python - ValueError : Length mismatch: Expected axis has 6 elements, 新值有 1 个元素

macos - 能够通过 Cyber​​duck SSH 到 EC2,但无法使用相同的凭据通过终端 SSH

macos - 附加到 protected 文件

objective-c - OSX/Xcode/Objective-C : How to detect the version of Flash Player installed?

objective-c - 我可以在 NSOutlineViews 中自定义 "Select All"吗?

macos - go install 命令结果在 open/bin/palindrome : operation not permitted in mac