[Python-3000] More PEP 3101 changes incoming

Ron Adam rrr at ronadam.com
Thu Aug 2 12:31:54 CEST 2007



Talin wrote:
> Ron Adam wrote:
> 
>> Splits the item and it's formatter.  The alignment is more of a 
>> container property or feild property as you pointed out further down.
>>
>> So maybe if you group the related values together...
>>
>>     {valuespec:format, alignment:width}
>>
>> This has a nice dictionary feel and maybe that may be useful as well. 
>> Reusing things I'm familiar with does make it easier.
> 
> I'm certainly open to switching the order of things around. Remember, 
> though, that we have *5* fields (6 depending on how you count) of 
> formatting options to deal with (see the PEP for details):
> 
>    -- alignment
>    -- padding char
>    -- minwidth
>    -- maxwidth
>    -- fractional digits
>    -- type
> 
> ...And we need to be able to represent these succinctly. That last is 
> important and here's why: None of these formatting codes are necessary 
> at all, because in the final analysis you can get the same effect by 
> wrapping the arguments to format() with the appropriate padding, 
> alignment, and type conversion function calls.
> 
> In other words, the whole point of these format codes is that they are 
> convenient shortcuts. And shortcuts by definition need to be *short*.
> 
> So we need to strike a balance between convenience and readability.
> 
> -- Talin

I wasn't thinking we would treat each option separately, just type, and 
alignment groups.  Within those, we would have pretty much what you have 
proposed.


Maybe it will help more to go a little slower instead of jumping in and 
offering a bunch of new alternatives.


What code specifies Decimals, "D"?


Any chance of thousands separators?


And what about exchanging comma's and decimals?


Does the following look complete, or needs anything added or removed?


Format Specifiers:
     As string:
         type           # [s|r]

     As integer:
         sign           # [-|+|()]
         fill_char      # character    \__ +07d -> +0000123
         fill_width     # number       /   fills with zeros
         type           # [b|c|d|o|x|X]  (*)

     As fixed point:
         sign           # [-|+|()]
         fill_char      # character
         fill_width     # number
         precision      # number       (fractional digits)
         type           # [e|E|f|F|g|G|n|%]


Alignment Specifiers:
     If formatted value is is shorter than min_width:
         align          # [<|>|^]
         min_width      # number
         padding_char   # character

     If formatted value is longer than max_width:
         max_width      # number



Cheers,
    Ron
















More information about the Python-3000 mailing list