[Python-ideas] str(<int>, base=<int>) as complement to int(<str>, base=<int>)

Christian Heimes lists at cheimes.de
Wed Oct 31 11:02:21 CET 2007


Hello!

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)
5
>>> int('a', 16)
10

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)
'101'
>>> str(10, 16)
'a'

I know it's not a killer feature but it feels right to have a
complement. How do you like the idea?

Christian




More information about the Python-ideas mailing list