Sunday, March 22, 2009

hexdumps in Python

I once had to decode hex strings that were in ASCII to the proper hex values.

I found this on the web:

map( ord, codecs.decode( '030109ff', 'hex' ) )


The more pythonic way would then be:

[ ord(x) for x in codecs.decode( '030109ff', 'hex' ) ]

Cool.

No comments: