[Python-ideas] str(<int>, base=<int>) as complement to int(<str>, base=<int>)
rrr at ronadam.com
Wed Oct 31 16:04:54 CET 2007
Steven Bethard wrote:
> On 10/31/07, Christian Heimes <lists at cheimes.de> wrote:
>> Python's int type has an optional argument base which allows people to
>> specify a base for the conversion of a string to an integer.
>>>>> int('101', 2)
>>>>> int('a', 16)
>> I've sometimes missed a way to reverse the process. How would you like
>> an optional second argument to str() that takes an int from 2 to 36?
>>>>> str(5, 2)
>>>>> str(10, 16)
>> I know it's not a killer feature but it feels right to have a
>> complement. How do you like the idea?
> This was discussed before:
> Seemed like people liked the concept, but there was a fair debate
> about syntax (should it be the str constructor, should it be an int
> method, etc.)
Or should it be a function in the math or string module?
More information about the Python-ideas