[python-win32] Problem with Raw datatype

Tim Roberts timr at probo.com
Sat Jun 9 00:18:29 CEST 2007


Larry Bates wrote:
> That is the value.  Since binary data doesn't print well, Python  prints
> the hex representation of each of the characters and puts \x in front of
> them so you will know that the string doesn't contain those characters
> but the hex they represent. Your database printed the hex representation
> but didn't give you any visual queue that would let you tell the difference
> between hex and ASCII characters.  You are just "supposed to know" that
> a raw column contains binary data.
>
> database   'FE  ED  EE  00  7F  91 500D   968  99 46  00  A3  C5  0C'
> Python   '\xfe\xed\xee\x00\x7f\x91 P\r  \x968\x99 F \x00\xa3\xc5\x0c'
>   

Just for completeness, there is one typo in the above; where you have
"968", the original was "96 38".  Since "38" is hex for the ASCII digit
8, your translation is still correct:

database   'FE  ED  EE  00  7F  91 50 0D   96 38  99 46  00  A3  C5  0C'
Python   '\xfe\xed\xee\x00\x7f\x91 P  \r \x96 8 \x99 F \x00\xa3\xc5\x0c'

I'm often surprised at how much confusion this causes.  For example, when presented with the Python string that prints as "\xfe", some people seem to think that it contains four bytes.  It does not.  It contains one byte, with the decimal value 254.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list