python阿拉伯编码问题 [英] python arabic encoding issue
本文介绍了python阿拉伯编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用Windows-1256编码的文本.现在我想将文本从阿拉伯语(windows-1256)转换为utf-8
i have a text with windows-1256 encoding. now i want to convert text from arabic(windows-1256) to utf-8
示例文本:
Óæí Ïæã ÈíåÞí
结果:
سوي دوم بيهقي
我使用此代码解码并编码为utf-8
i use this code to decode and encod to utf-8
# -*- coding: utf-8 -*-
data = "Óæí Ïæã ÈíåÞí"
print data.decode("windows-1256", "replace")
print data.encode("windows-1256")
该代码返回以下结果:
أ"أ¦أ أڈأ¦أ£ أˆأأ¥أأ
Traceback (most recent call last):
File "mohmal2.py", line 5, in <module>
print data.encode("windows-1256")
File "/usr/lib/python2.7/encodings/cp1256.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
我找到了可以转换此文本的网站:
i found a site that can convert this text:
查看全文