[Python-3000] More PEP 3101 changes incoming

Jim Jewett jimjjewett at gmail.com
Tue Aug 14 21:33:20 CEST 2007


On 8/13/07, Ron Adam <rrr at ronadam.com> wrote:
> I reconsidered the split term forms a bit more and I think I've come up
> with a better way to think about them. Sometimes a slight conceptual
> shift can make a difference.

> The basic form is:

>        {name[:][type][alignment_term][,content_modifying_term]}

That sounds good, but make sure it works in practice; I think you were
already tempted to violate it yourself in your details section.  You
used the (alignment term) width as the number of digits before the
decimal, instead of as the field width.

> TYPE:
>         The specifier type.  One of 'deifsrx'.
>                 (and any others I left off)

There should be one that says "just trust the object, and if it
doesn't have a __format__, then gripe".  (We wouldn't need to support
arbitrary content_modifying_terms unless it were possible to use more
than the builtin types.)

> ALIGNMENT TERM:   [direction]width[/fill]
>
>      direction:    is one of   '<^>'
>      width:        a positive integer
>      /fill:         a character


So this assumes fixed-width, with fill?

Can I leave the width off to say "whatever it takes"?

Can I say "width=whatever it takes, up to 72 chars ... but don't pad
it if you don't need to"?

(And once you support variable-width, then minimum is needed again.)

I'm not sure that variable lengths and alignment even *should* be
supported in the same expression, but it forcing everything to
fixed-width would be enough of a change that it needs an explicit
callout.

>      NUMBERS:   [sign][0][digits][.decimals][%]

I read Greg's question:

    How does this work with formats where the number of
    digits before the decimal can vary, but before+after
    is constant?

differently, as about significant figures.  It may be that 403 and
14.1 are both valid values, but 403.0 would imply too much precision.
(Would it *always* be OK to write these as 4.03e+2 and 1.41e+1?)

Maybe the answer is that sig figs are a special case, and need a
template with callbacks instead of a format string ... but that
doesn't feel right.

>      /fill:         a character

I think you need to specify it a bit more than that.  Can you use a
comma?  (It looks like the start of the content modifier.)  How about
a quote-mark, or a carriage return?

-jJ


More information about the Python-3000 mailing list