How convert string '1e7' to an integer?

Tim Chase python.list at tim.thechases.com
Sat Nov 7 21:05:22 EST 2009


Mick Krippendorf wrote:
> Peng Yu wrote:
>> It seems that int() does not convert '1e7'.
> It seems it does, though:
> 
>>>> int('1e7', base=16)
> 487

Bah...so narrow-minded ;-)

 >>> print '\n'.join("Base %i: %i" % (base, int('1e7', 
base=base)) for base in range(15,37))
Base 15: 442
Base 16: 487
Base 17: 534
Base 18: 583
Base 19: 634
Base 20: 687
Base 21: 742
Base 22: 799
Base 23: 858
Base 24: 919
Base 25: 982
Base 26: 1047
Base 27: 1114
Base 28: 1183
Base 29: 1254
Base 30: 1327
Base 31: 1402
Base 32: 1479
Base 33: 1558
Base 34: 1639
Base 35: 1722
Base 36: 1807

I feel so dirty interpreting numbers in convenient ways...like an 
accountant.  ("whaddaya mean I can't file my tax-return in base 
17?!  There's nothing in the supporting documentation that 
mentions such draconian restrictions!")

-tkc







More information about the Python-list mailing list