Odd problem with converting string to Hex?

Emile van Sebille emile at fenx.com
Sun Jul 1 10:57:19 EDT 2001


>>> t = ('.1.3.6.1.2.1.2.2.1.6.2', '\x00\x90\x83H\x11\x0f')
>>> t[1]
'\000\220\203H\021\017'
>>> mask = "-".join(["%02X"]*len(t[1]))
>>> print mask % tuple(map(ord,list(t[1])))
00-90-83-48-11-0F
>>>

Watch out for the extra 'H' in your data - you skip over it in your desired
result.

HTH,

--

Emile van Sebille
emile at fenx.com

---------
"Benjamin Schollnick" <junkster at rochester.rr.com> wrote in message
news:junkster-AB6FEA.10163501072001 at typhoon1-0.nyroc.rr.com...
> Folks,
>
>    This is odd.... or at least I think it is....
>
>    Using Python v2.1....
>
>    Here's a snippet of the data:
>
> ('.1.3.6.1.2.1.2.2.1.6.2', '\x00\x90\x83H\x11\x0f'),
> ('.1.3.6.1.2.1.2.2.1.6.1', '\x00\x90\x83H\x11\x0f'),
> ('.1.3.6.1.2.1.2.2.1.2.4', 'RF Upstream Interface')
>
>    I've tried using:
>
>       eval (data[1])
>       hex (data[1])
>       str(data[1])
>
>    What gets returned is:
>
>    Unknown - Mac?  --->    êÉH
>             Hex:            Long:
>
>    Which os definetly not what I'm looking for.... I'm attempting to
> decode this in pure hexadecimal...
>
>    I suspect it's due to the "\x" in the string, but I can't pull up the
> documentation, since when I tried I wasn't getting a response from
> python.org.....
>
>    Conceptually I'm trying to output it, similiar to:
>
>       00-90-83-11-0f    Assuming I'm reading the returned data properly.
>
>          - Benjamin





More information about the Python-list mailing list