Thursday, March 5, 2020

Python code tis-620 to utf-8

Ref:


# tis-620 to utf-8
    def thai2unicode(self, data): # for python 2 convert thai to unicode
        # print("in th2uni")
        result = ''
        if isinstance(data, list):
            for d in data:
                if (sys.version_info.major < 3):
                    result += unicode(chr(d),"tis-620")
                else :
                    result += chr(d).decode("tis-620").encode("utf-8")
        else :
            result = data.decode("tis-620").encode("utf-8")
        return result.strip()


    def thai2unicode2(self, data): # for python 3 convert thai to unicode
        result = ''
        result = bytes(data).decode('tis-620')
        return result.strip();

No comments:

Post a Comment