0

I am currently querying a kdb system and it is returning the data in bytes. Specifically in one column, I am getting a byte object that looks likes this

b'US $ to UK \xa3 (TTF)'

If I want to decode the string version of this, I can do the following and this works:

result = 'US $ to UK \xa3 (TTF)'.encode().decode()

But I couldn't figure out a way to decode the byte object, any suggestions?

I've tried

b'US $ to UK \xa3 (TTF)'.decode() 

but this gives an exception as the \xa3 is not encoded yet, is there a way to convert this byte object into a string literal without decoding?

1 Answer 1

1

The encoding of that string seems to be ISO-8859-1 (a.k.a. Latin-1), not UTF-8. Once you decode the string correctly, you will be able to work with it or encode it to some other encoding like UTF-8.

raw = b'US $ to UK \xa3 (TTF)'
text = raw.decode('ISO-8859-1')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.