int() shortcoming?
Padraig Brady
Padraig at Linux.ie
Fri Nov 22 09:53:30 EST 2002
Padraig Brady wrote:
> Matthew Knepley wrote:
>
>> Is there a reason I should have to specify the base for a string
>> conversion using int() when it is already clear from the form? For
>> instance:
>>
>>>>> oct(15)
>>>>
>> '017'
>>
>>>>> int('017')
>>>>
>> 17
>>
>>>>> int('017', 8)
>>>>
>> 15
>>
>> and hexidecimal actually generates an error.
>
> I agree with you somewhat.
> I think int() be default should behave like strtol(nptr, (char **)NULL, 0)
> rather than strtol(nptr, (char **)NULL, 10);
> However this is not backwards compatible.
> I.E. int('017') would give a different answer.
>
> see also:
> http://tardis.redbrick.dcu.ie/391/groups.google.com
I should also mention you can also run eval on the string
first to get the functionality you want + extra functionality, like:
int(eval("1.2"))
int(eval("1e3"))
int(eval("1L"))
Pádraig.
More information about the Python-list
mailing list