[Python-3000] More PEP 3101 changes incoming
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Aug 7 11:33:51 CEST 2007
Ron Adam wrote:
> What about mismatched specifiers?
It's not clear exactly what you mean by a "mismatched"
specifier.
Some types may recognise when they're being passed
a format spec that belongs to another type, and try
to convert themselves to that type (e.g. applying
'f' to an int or 'd' to a float).
If the type doesn't recognise the format at all,
and doesn't have a fallback type to delegate to
(as will probably be the case with str) then
you will get an exception.
> I think the opinion so far is to let the objects __format__ method
> determine this, but we need to figure this out what the built in types
> will do.
My suggestions would be:
int - understands all the 'integer' formats
(d, x, o, etc.)
- recognises the 'float' formats ('f', 'e', etc.)
and delegates to float
- delegates anything it doesn't recognise to str
float - understands all the 'float' formats
- recognises the 'integer' formats and delegates to int
- delegates anything it doesn't recognise to str
str - recognises the 'string' formats (only one?)
- raises an exception for anything it doesn't understand
I've forgotten where 'r' was supposed to fit into
this scheme. Can anyone remind me?
--
Greg
More information about the Python-3000
mailing list