[Python-3000] More PEP 3101 changes incoming

Talin talin at acm.org
Mon Aug 6 07:40:07 CEST 2007


Greg Ewing wrote:
> Talin wrote:
>> in 
>> the case of an integer that is printed with leading zeros, the sign must 
>> come *before* the padding: '+000000010'. It's not sufficient to simply 
>> apply padding blindly to the output of __format__, which would give you 
>> '000000+10'.
> 
> How about this, then: The apply_format function parses
> the alignment spec and passes the result to the __format__
> method along with the format spec. The __format__ method
> can then choose to do its own alignment and padding to
> achieve the specified field width. If it returns something
> less than the specified width, apply_format then uses the
> default alignment algorithm.
> 
> Then the __format__ method has complete control over the
> whole process if it wants, the only distinction being that
> the alignment spec has a fixed syntax whereas the format
> spec can be anything.

I think that this is right - at least, I can't think of another way to 
do it.

-- Talin


More information about the Python-3000 mailing list