Python version of binascii.b2a_hex (binary to hex conversion)?
Barry A. Warsaw
barry at digicool.com
Fri Apr 27 18:16:36 EDT 2001
>>>>> "GG" == Graham Guttocks <graham_guttocks at yahoo.co.nz> writes:
GG> Greetings Barry,
GG> I don't mean to look a gift horse in the mouth so to speak,
GG> but is there a way to unhexlify using all builtins such as
GG> what I've done with hexlify here?
| def hexlify(b):
| return "%02x"*len(b) % tuple(map(ord, b))
Well, depends on how you define `builtins' :) Do you mean functions
in the builtin module, or C builtin functions? Or are you looking for
a convenient one-liner?
Essentially the unhexlify I posted uses only C builtin functions,
e.g. [].append, strop.atoi, range, len, chr, strop.join. I don't
remember if anybody came up with a nice one-liner when the thread was
debated eons ago.
Cheers,
-Barry
More information about the Python-list
mailing list