[Python-3000] Should int() and float() accept bytes?
Guido van Rossum
guido at python.org
Wed Apr 16 00:06:18 CEST 2008
On Tue, Apr 15, 2008 at 2:56 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
>
> On Tue, Apr 15, 2008 at 2:37 PM, Gregory P. Smith <greg at krypto.org> wrote:
> > Agreed. Otherwise the common ascii based network protocol task of reading
> some bytes in and converting them to the integer that they represent in
> ascii would require an additional unicode decoding step.
> >
>
> This use-case doesn't seem particularly convincing when the reverse step of
> converting an integer to an (ascii) bytes instance still has to go through
> unicode.
> Maybe there should be an int.to_ascii method?
Input and output are often wildly asymmetric anyway. It's easy to make
int() and float() accept more input types. But making them return a
different output type is different. I find the existing work-arounds
good enough not to propose a whole new API. If we end up deciding to
add one anyway, I don't think that to_ascii is a good name; it doesn't
imply the type of the result, since ASCII text can also be (and
usually is) represented as a (Unicode) str instance.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list