[Python-Dev] Python Language Summit EuroPython 2010

Guido van Rossum guido at python.org
Fri Jul 23 08:44:42 CEST 2010


On Thu, Jul 22, 2010 at 6:50 PM, Eric Smith <eric at trueblade.com> wrote:
> Thanks for writing this, Tim.
>
> On 7/21/10 11:11 AM, Tim Golden wrote:
>
>> The issue of a __format__ equivalent for bytes was also raised as was the
>> idea of object methods to render an object as string or bytes, which could
>> be used in the polymorphic functions above.
>
> Does this mean bytes.__format__, or does it mean bytes.format?
> bytes.__format__ already exists, but it just calls object.__format__. I'm
> not sure what the desired functionality for bytes.__format__ would be.
>
> If it means bytes.format, this would be relatively easy to do in CPython, if
> there's agreement to add it.

Indeed, we meant b'...{}...{}...'.format(x, y). The problem is that it
can't invoke x.__format__() or y.__format__() since those will return
text strings instead of bytes. A proposed solution was to try
x.__bformat__() etc. Another proposed solution was to limit x and y to
a small set of common types and hard-code their meanings (e.g.
numbers, bytes, and dates).

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list