[Python-3000] More PEP 3101 changes incoming

Nick Coghlan ncoghlan at gmail.com
Mon Aug 6 13:02:35 CEST 2007


Talin wrote:
> 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.

Heh, I could have saved myself some typing by reading more before replying.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list