[Python-3000] More PEP 3101 changes incoming
Ron Adam
rrr at ronadam.com
Tue Aug 7 22:26:54 CEST 2007
Talin wrote:
> Ron Adam wrote:
>> Now here's the problem with all of this. As we add the widths back
>> into the format specifications, we are basically saying the idea of a
>> separate field width specifier is wrong.
>>
>> So maybe it's not really a separate independent thing after all, and
>> it just a convenient grouping for readability purposes only.
>
> I'm beginning to suspect that this is indeed the case.
Yes, I believe so even more after experimenting last night with specifier
objects.
for now I'm using ','s for separating *all* the terms. I don't intend that
should be used for a final version, but for now it makes parsing the terms
and getting the behavior right much easier.
f,.3,>7 right justify in field width 7, with 3 decimal places.
s,^10,w20 Center in feild 10, expands up to width 20.
f,.3,%
This allows me to just split on ',' and experiment with ordering and see
how some terms might need to interact with other terms and how to do that
without having to fight the syntax problem for now.
Later the syntax can be compressed and tested with a fairly complete
doctest as a separate problem.
> Before we go too much further, let me give out the URLs for the .Net
> documentation on these topics, since much of the current design we're
> discussing has been inspired by .Net:
>
> http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx
> http://msdn2.microsoft.com/en-us/library/0c899ak8.aspx
> http://msdn2.microsoft.com/en-us/library/0asazeez.aspx
> http://msdn2.microsoft.com/en-us/library/c3s1ez6e.aspx
> http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx
> http://msdn2.microsoft.com/en-us/library/txafckwd.aspx
>
> I'd suggest some study of these. Although I would warn against adopting
> this wholesale, as there are a huge number of features described in
> these documents, more than I think we need.
>
> One other URL for people who want to play around with implementing this
> stuff is my Python prototype of the original version of the PEP. It has
> all the code you need to format floats with decimal precision,
> exponents, and so on:
>
> http://www.viridia.org/hg/python/string_format?f=5e4b833ed285;file=StringFormat.py;style=raw
Thanks, I'll take a look at it.
Cheers,
Ron
More information about the Python-3000
mailing list