[Tutor] get bytes back from string representation?
alan.gauld at btinternet.com
Mon Apr 13 09:32:21 CEST 2009
"Daniel" <daniel.chaowang at gmail.com> wrote
Caveat, I know nothing about SUDS.
> rawByte =
> the problem is I need to convert the rawByte from string to bytes, then
> explain it as text with encoding (like "UTF-8").
A string is a collection of bytes. What you see when you print a string is
just the interpretation of those bytes as characters. So the real question
is how do you want to interpret the bytes? What do the bytes represent?
For example are they in a different character encoding, perhaps unicode?
In that case simple changing the string encoding (and locale serttings?)
should enable you to print them as a string.
Or do they represent binary data such as numbers or objects that need
to be extracted and then turned into string representation. In that case
you may need to use the struct module.
It all depends on what the bytes actually represent.
Author of the Learn to Program web site
More information about the Tutor