[Python-ideas] str(<int>, base=<int>) as complement to int(<str>, base=<int>)
Guido van Rossum
guido at python.org
Wed Oct 31 17:49:24 CET 2007
It should *definitely* *not* be the str() constructor, which is
already overloaded. Remember str() takes arguments of *any* type.
Overloading variants on the conversion to string via arguments to
str() doesn't scale.
On 10/31/07, Steven Bethard <steven.bethard at gmail.com> 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)
> > 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?
> 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.)
> I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
> tiny blip on the distant coast of sanity.
> --- Bucky Katt, Get Fuzzy
> Python-ideas mailing list
> Python-ideas at python.org
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas