how to transfer my utf8 code saved in a file to gbk code

R. David Murray rdmurray at
Sun Jun 7 10:13:45 EDT 2009

higer <higerinbeijing at> wrote:
> My file contains such strings :
> \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a

If those bytes are what is in the file (and it sounds like they are),
then the data in your file is not in UTF8 encoding, it is in ASCII
encoded as hexidecimal escape codes.

> I want to read the content of this file and transfer it to the
> corresponding gbk code,a kind of Chinese character encode style.

You'll have to convert it from hex-escape into UTF8 first, then.

Perhaps better would be to write the original input files in UTF8,
since it sounds like that is what you were intending to do.

R. David Murray       
    IT Consulting    System Administration    Python Programming

More information about the Python-list mailing list