[Python-Dev] PEP 461 updates (original) (raw)

Ethan Furman ethan at stoneleaf.us
Fri Jan 17 02:51:43 CET 2014


On 01/16/2014 05:32 PM, Greg wrote:

I don't think it matters whether the internal details of that debate make sense to the rest of us. The main thing is that a consensus seems to have been reached on bytes formatting being basically a good thing.

And a good thing, too, on both counts! :)

A few folks have suggested not implementing .format() on bytes; I've been resistant, but then I remembered that format is also a function.

http://docs.python.org/3/library/functions.html?highlight=ascii#format

format(value[, format_spec])

 Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec 

will depend on the type of the value argument, however there is a standard formatting syntax that is used by most built-in types: Format Specification Mini-Language.

 The default format_spec is an empty string which usually gives the same effect as calling str(value).

 A call to format(value, format_spec) is translated to type(value).__format__(format_spec) which bypasses the 

instance dictionary when searching for the value’s format() method. A TypeError exception is raised if the method is not found or if either the format_spec or the return value are not strings.

Given that, I can relent on .format and just go with .mod . A low-level service for a low-level protocol, what? ;)

-- Ethan



More information about the Python-Dev mailing list