python-unicode

String.maketrans for English and Persian numbers

String.maketrans for English and Persian numbers Question: I have a function like this: persian_numbers = ‘۱۲۳۴۵۶۷۸۹۰’ english_numbers = ‘1234567890’ arabic_numbers = ‘١٢٣٤٥٦٧٨٩٠’ english_trans = string.maketrans(english_numbers, persian_numbers) arabic_trans = string.maketrans(arabic_numbers, persian_numbers) text.translate(english_trans) text.translate(arabic_trans) I want it to translate all Arabic and English numbers to Persian. But Python says: english_translate = string.maketrans(english_numbers, persian_numbers) ValueError: maketrans arguments must …

Total answers: 8

Python string to unicode

Python string to unicode Question: Possible Duplicate: How do I treat an ASCII string as unicode and unescape the escaped characters in it in python? How do convert unicode escape sequences to unicode characters in a python string I have a string that contains unicode characters e.g. u2026 etc. Somehow it is not received to …

Total answers: 3

UnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128)

UnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position 20: ordinal not in range(128) Question: I’m having problems dealing with unicode characters from text fetched from different web pages (on different sites). I am using BeautifulSoup. The problem is that the error is not always reproducible; it sometimes works with some pages, and sometimes, it …

Total answers: 34

Python – 'ascii' codec can't decode byte

Why does ENcoding a string result in a DEcoding error (UnicodeDecodeError)? Question: I’m really confused. I tried to encode but the error said can’t decode…. >>> “你好”.encode(“utf8”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe4 in position 0: ordinal not in range(128) I know how …

Total answers: 7