[Python-3000] More PEP 3101 changes incoming

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Aug 6 03:08:46 CEST 2007


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.

--
Greg


More information about the Python-3000 mailing list