sorting a list numbers stored as strings

Delaney, Timothy (Tim) tdelaney at avaya.com
Wed Sep 26 05:40:24 EDT 2007


ZeD wrote:

> thebjorn wrote:
> 
>>>>>> int("020")
>>> 20
>>>>>> 020
>>> 16
>> 
>> You can get the latter behavior using eval:
> 
> why using eval when int has the "base" optional parameter?
> 
>>>> int("020")
> 20
>>>> int("020", 8)
> 16
>>>> int("09", 8)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: invalid literal for int() with base 8: '09'

The whole point of this was I misremembered what the base/radix optional
parameter of int() defaulted to - I thought it was 0, then when I
checked in Python 2.5 I thought it must have been 0 in an earlier
version.

Tim Delaney



More information about the Python-list mailing list