[Python-3000] More PEP 3101 changes incoming

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 8 03:14:47 CEST 2007


Ron Adam wrote:
> 
> Greg Ewing wrote:
 >
>> 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).
> 
> After thinking about this a bit more, I think specifiers don't have 
> types and don't belong to types.

I agree - I was kind of speaking in shorthand there.
What I really meant was that some types have some knowledge
of format specifiers recognised by other types. E.g.
int doesn't itself know how to format something using
a spec that starts with 'f', but it knows that float
*does* know, so it converts itself to a float and
lets float handle it from there.

If you were to pass an 'f' format to something that
had no clue about it at all, e.g. a datetime, you
would ultimately get an exception. And there's
nothing stopping another type from recognising
'f' and doing something of its own with it that
doesn't involve conversion to float (e.g. decimal).

So the one-to-many mapping you mention is accommodated.

--
Greg


More information about the Python-3000 mailing list