Skip to content Skip to sidebar Skip to footer

Unable To Decode This String Using Python

I have this text.ucs file which I am trying to decode using python. file = open('text.ucs', 'r') content = file.read() print content My result is \xf\xe\x002\22 I tried doing dec

Solution 1:

The string is encoded as UTF16-BE (Big Endian), this works:

content.decode("utf-16-be")

Solution 2:

oooh, as i understand you using python 2.x.x but encoding parameter was added only in python 3.x.x as I know, i am doesn't master of python 2.x.x but you can search in google about io.open for example try:

file = io.open('text.usc', 'r',encoding='utf-8')
content = file.read()
print content

but chek do you need import io module or not

Solution 3:

You can specify which encoding to use with the encoding argument:

withopen('text.ucs', 'r', encoding='utf-16') as f:
    text = f.read()

Solution 4:

your string need to Be Uncoded With The Coding utf-8 you can do What I Did Now for decode your string

f = open('text.usc', 'r',encoding='utf-8')
print f

Post a Comment for "Unable To Decode This String Using Python"