[Python-3000] More PEP 3101 changes incoming
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Aug 10 02:30:38 CEST 2007
Ron Adam wrote:
> The way to think of 'repr' and 'str' is that of a general "object" format
> type/specifier. That puts str and repr into the same context as the rest
> of the format types. This is really a point of view issue and not so much
> of a semantic one. I think {0:r} and {0:s} are to "object", as {0:d} and
> {0:e} are to "float" ... just another relationship relative to the value
> being formatted. So I don't understand the need to treat them differently.
There's no need to treat 's' specially, but 'r' is different,
at least if we want
"{0:r}".format(x)
to always mean the same thing as
"{0:s}".format(repr(x))
To achieve that without requiring every __format__ method
to recognise 'r' and handle it itself is going to require
format() to intercept 'r' before calling the __format__
method, as far as I can see. It can't be done by str,
since by the time str.__format__ gets called, the object
has already been passed through str(), and it's too late
to call repr() on it.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | Carpe post meridiem! |
Christchurch, New Zealand | (I'm not a morning person.) |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-3000
mailing list