Dumb python questions

Bengt Richter bokr at accessone.com
Sun Aug 19 02:49:08 CEST 2001


On Sun, 19 Aug 2001 00:06:18 GMT, bokr at accessone.com (Bengt Richter) wrote:
[...]

>That ought to hold the string, and is confirmed by
> >>> len(s)
> 27294
>
>That's not the exact number of bits, so define a function like so:
           ^--necessarily           ^--if multiplied by 8
> >>> import math
> >>> def bitsin(x):
> ...     return math.frexp(eval(hex(x)[:3]))[1]+4*(len(hex(x))-4)
> ...
> >>> bitsin(7**77777L)
> 218348
Of course you wouldn't do hex(x) twice if you weren't interactively
building up the expression ;-)
Maybe
 >>> def bitsin(x):
 ...     h = hex(long(x))
 ...     return math.frexp(eval(h[:3]))[1]+4*(len(h)-4)




More information about the Python-list mailing list