"Benjamin Peterson" <b...@phon.org> wrote:

>So called encodings like "hex" and "rot13" are abuse of
>encode() method. encode() should translate
>between byte strings and unicode, not preform
>transformations like that. This has been removed
>in 3.x, so you should use binascii.

When all else fails, and just for fun, go to first principles:

>>> hextab = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
>>> s = 'the quick brown fox jums OVER the lazy dog'
>>> h = []
>>> for x in s:
           h.append(hextab[ord(x)>>4])
           h.append(hextab[ord(x)&15])

>>> print ''.join(h)
74686520717569636B2062726F776E20666F78206A756D73204F56455220746865206C617A792064
6F67
>>>

- Hendrik








--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to