[Python-3000] More PEP 3101 changes incoming

Ron Adam rrr at ronadam.com
Tue Aug 14 05:44:38 CEST 2007



Greg Ewing wrote:
> Ron Adam wrote:
> 
>> The digits value are number of digits before the decimal.  This doesn't 
>> include the other symbols used in the field so it isn't the same as a field 
>> width.
> 
> How does this work with formats where the number of
> digits before the decimal can vary, but before+after
> is constant?

I think this is what you're looking for.

    f>15,.3   #15 field width, 3 decimal places, right aligned.

In this case the sign will be right before the most significant digit.

Or you could use...

    f 10.3   # total width = 15

In this one, the sign would be to the far left of the field.  So they are 
not the same thing.  The space is used here to make positives numbers the 
same width as negatives values.


> Also, my feeling about the whole of this is that
> it's too complicated. It seems like you can have
> at least three numbers in a format, and at first
> glance it's quite confusing as to what they all
> mean.

Well, at first glance so is everything else that's been suggested,  it's 
because we are doing a lot in a very little space.  In this case we are 
adding just a touch of complexity to the syntax in order to use grouping to 
remove complexity in understanding the expression.

These are all field width terms:

     >10       right align in field 10
     ^15/_     center in field 15, pad with underscores
     20/*      left align in field 20, pad with *

They are easy to identify because other terms do not contain '<^>/'. And 
sense they are separate from other format terms, once you get it, you've 
got it. Nothing more to remember here.

It doesn't make sense to put signs in front of field widths because the 
signs have no relation to the field width at all.


These are all number formats:

     +10.4
     (10.4)
     .6
     ' 9.3'     Quoted so you can see the space.
     10.

Here, we don't use alignment symbols.  Alignments have no meaning in the 
context of number of digits.  So these taken as a smaller chunk of the 
whole will also be easier to remember.  There are no complex interactions 
between field alignment terms, and number terms this way.  That makes 
simpler to understand and learn.


Lets take apart the alternative syntax.

     f<+15.2

       f   fixed point     # of decimals is specified

       <   align left      (field attribute)

       +   sign            (number attribute)

       15  width           (field attribute)

       .2  decimals        (number attribute)

So what you have is some of them apply to the field with and some of them 
effect how the number is displayed.  But they alternate.  (Does anyone else 
find that kind of odd?)

The specifier syntax described here groups related items together.

    f<15,-.2

    f   fixed point

    <     left align
    15    field width

    +     sign
    .2    decimals


Yes, we can get rid of one number by just using the field width in place of 
a digits width.  But it's a trade off.  I think it complicates the concept 
in exchange for simplifying the syntax.

Regards,
    Ron














More information about the Python-3000 mailing list