[Tutor] get bytes back from string representation?

Alan Gauld 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 = 
> "PGh0bWw+PGhlYWQ+PG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb2

> 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.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list