[Python-3000] More PEP 3101 changes incoming

Nick Coghlan ncoghlan at gmail.com
Mon Aug 6 12:58:13 CEST 2007


Talin wrote:
> Of course, the two can't be entirely isolated because there is 
> interaction between the two specifiers for some types. For example, it 
> would normally be the case that padding is applied by 'apply_format', 
> which knows about the field width and the padding character. However, 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'.
> 
> (Maybe leading zeros and padding are different things? But the 
> __format__ would still need to know the field width, which is usually 
> part of the alignment spec, since it's usually applied as a 
> post-processing step by 'apply_format')

Is the signature of __format__ up for negotiation?

If __format__ receives both the alignment specifier and the format 
specifier as arguments, then the method would be free to return its own 
string that has already been adjusted to meet the minimum field width. 
Objects which don't care about alignment details can just return their 
formatted result and let the standard alignment handler deal with the 
minimum field width.

Cheers,
Nick.

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


More information about the Python-3000 mailing list