A 'raw' codec for binary "strings" in Python?

Erik Max Francis max at alcyone.com
Mon Mar 1 23:12:16 EST 2004


Bill Janssen wrote:

> You'll notice that
> the problem is in *decoding* the string, not in re-encoding it,
> because I'm using the default "C" locale, and "US-ASCII" is presumed
> for strings.  But these strings are *not* US-ASCII, they are raw
> bytes.  How do I format a string of raw bytes for conversion to a
> recognized charset encoding for printing?

Since the default encoding is ASCII, those 8-bit octets have no meaning
unless you do an explicit conversion.  Trying to print them _should_
raise an error, because you're trying to do something that doesn't make
sense.

As Gerrit pointed out, it sounds like what you want is repr.

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Liberty is the right to do whatever the law permits.
    -- Charles Louis Montesquieu



More information about the Python-list mailing list