Cryptographically random numbers

Bryan Olson fakeaddress at nowhere.org
Tue Mar 7 04:34:58 CET 2006


Paul Rubin wrote:
> My favorite way to convert strings to numbers is with binascii:
 >
>  from binascii import hexlify
>  def s2num(text):
>    return int(hexlify(text), 16)


Neat. I use the empty string as a binary representation of zero,
which you can accommodate with:

def s2num(text):
     return int(hexlify(text) or '0', 16)


-- 
--Bryan



More information about the Python-list mailing list