python - 为什么 rst2html5 会搞乱编码?

标签 python windows powershell character-encoding

我有一个 Python 程序,它是用 PyCharm 和 Sublime Text 确认的 UTF-8 编写的。它打印出井号字符,£ ( 0xC2 0xA3 ),到重组文本:

enter image description here

用 PyCharm 和 Sublime Text 打开重组文本文件,它看起来不错,并且都声称它是 UTF-8。

当我使用 rst2html5 从此文件生成 HTML 时,问题就来了, 使用此命令:

 rst2html5 --input-encoding=utf-8 --output-encoding=utf-8 foo.rst > foo.html

HTML 声称是 UTF-8,通过 <meta charset="utf-8" /> ,但是井号字符,£ , 现在显示为 ┬ú .在 Sublime Tex 中以 UTF-8 格式打开它也会显示 ┬ú而不是 £ .这是实际数据:

enter image description here

知道发生了什么或如何阻止它吗?这看起来像 UTF-8 吗?

生成的文件是这样开头的:

enter image description here

0xFF 0xFE让我想起了UTF-16 BOM但将 header 设置为 <meta charset="utf-16" />没有解决问题并告诉文本编辑器打开文件,因为 UTF-16 仍然显示非 ASCII 字符损坏。

如果相关,我的事件 Windows 代码页是 437。

最佳答案

问题是由 PowerShell 重定向引起的,而不是由 rst2html5 本身引起的。像这样运行它:

 rst2html5 --input-encoding=utf-8 --output-encoding=utf-8 foo.rst foo.html

与重定向 (>) 具有相同效果的效果很好,在 CMD 上使用重定向也很好。

如果有人知道有关 PowerShell 为何搞乱编码的更多信息,最好在此处添加。

关于python - 为什么 rst2html5 会搞乱编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53516499/

相关文章:

json - 批量导入JSON到SQL Server

python - 资源耗尽错误:OOM when allocating tensor with shape []

windows - WinDbg 显示一些变量但不显示其他变量,在同一位置显示一些变量

windows - PST复制批处理文件添加进度条

windows - 在 Windows 上使用 Azure CLI 颁发证书链中的自签名证书

powershell - 如何在PowerShell中获取详细的异常

python - 与 4 之和相切的组合的组合

python - NoBrokersAvailable : NoBrokersAvailable-Kafka Error

python - 将 list[adodbapi.apibase.SQLrow] 转换为 pd.DataFrame

powershell - 如何将这个不同的属性名称保存到单个公共(public)属性中?