我有一些以ASCII格式存储的旧数据。很明显,UTF-8数据在被写入之前没有正确地转换成ASCII。例如,José
将在文件中显示为José
。我可以用下面的Java代码片段轻松解决这个问题:
byte[] utf8Bytes = c_TOBETRANSLATED.getBytes("ISO-8859-1");
String s2 = new String(utf8Bytes,"UTF-8");
但是我需要用我剩下的代码来完成这个Python。我只是刚刚开始使用Python,我的互联网搜索和试错并不能帮助我找到一个Python解决方案来做同样的事情。你知道吗
如果文件中有
"José"
,则文件查看器读取/显示的数据不正确。它是UTF-8,但是用错误的编码解码。示例:输出:
如果您使用的是Python 3,那么可以使用bytes function执行以下操作:
相关问题 更多 >
编程相关推荐