python-2.7thai

Convert \xc3\xd8\xe8\xa7\xc3\xb4\xd to human readable format


I am having trouble converting '\xc3\xd8\xe8\xa7\xc3\xb4\xd' (which is a Thai text) to a readable format. I get this value from a smart card, and it basically was working for Windows but not in Linux.

If I print in my Python console, I get:

����ô

I tried to follow some google hints but I am unable to accomplish my goal.

Any suggestion is appreciated.


Solution

  • Your text does not seem to be a Unicode text. Instead, it looks like it is in one of Thai encodings. Hence, you must know the encoding before printing the text.

    For example, if we assume your data is encoded in TIS-620 (and the last character is \xd2 instead of \xd) then it will be "รุ่งรดา".

    To work with the non-Unicode strings in Python, you may try: myString.decode("tis-620") or even sys.setdefaultencoding("tis-620")