[Python-3000] Should int() and float() accept bytes?
Gregory P. Smith
greg at krypto.org
Tue Apr 15 20:37:04 CEST 2008
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.
On Tue, Apr 15, 2008 at 7:18 AM, Guido van Rossum <guido at python.org> wrote:
> Yeah, practicalibty beat purity on that one. I'd say let it beat
> purity on int() and float() as well.
>
> On Tue, Apr 15, 2008 at 2:42 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > Mark Dickinson wrote:
> > > On the other hand, there's at least some sense in which bytes already
> > > acts as a sort of poor-man's string: witness bytes.lower and friends.
> > > Maybe practicality beats purity here?
> >
> > From PEP 358 (describing what is now bytearray):
> >
> > """Note the conspicuous absence of .isupper(), .upper(), and friends.
> > (But see "Open Issues" below.) There is no .__hash__() because
> > the object is mutable."""
> >
> > And the open issue:
> >
> > """A case could even be made for supporting .islower(), .isupper(),
> > .isspace(), .isalpha(), .isalnum(), .isdigit() and the
> > corresponding conversions (.lower() etc.), using the ASCII
> > definitions for letters, digits and whitespace. If this is
> > accepted, the cases for .ljust(), .rjust(), .center() and
> > .split() become much stronger, and they should have default
> > arguments as well, using an ASCII space or all ASCII whitespace
> > (for .split())."""
> >
> > PEP 3157 resolved that open issue as follows:
> >
> > """This is exactly the set of methods present on the str type in Python
> > 2.x, with the exclusion of .encode(). The signatures and semantics are
> > the same too. However, whenever character classes like letter,
> > whitespace, lower case are used, the ASCII definitions of these classes
> > are used."""
> >
> >
> > That seems fairly explicit to me in saying that a bytes or bytearray
> > object should be considered to be ASCII encoded when treated as a
> string.
> >
> > Cheers,
> > Nick.
> >
> > --
> > Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
> > ---------------------------------------------------------------
> > http://www.boredomandlaziness.org
> >
> >
> > _______________________________________________
> > Python-3000 mailing list
> > Python-3000 at python.org
> > http://mail.python.org/mailman/listinfo/python-3000
> > Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/guido%40python.org
> >
>
>
>
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/<http://www.python.org/%7Eguido/>
> )
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/greg%40krypto.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20080415/9540e0ba/attachment-0001.htm
More information about the Python-3000
mailing list