[Python-3000] More PEP 3101 changes incoming
Ron Adam
rrr at ronadam.com
Tue Aug 14 16:20:26 CEST 2007
Walter Dörwald wrote:
>> 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)
>
> Then why not have something more readable like
>
> al;s+;w15;d2
>
> This is longer that <+15.2, but IMHO much more readable, because it's
> clear where each specifier ends and begins.
>
> Servus,
> Walter
Well depending on what its for that might very well be appropriate, It's
order independent, and has other benefits, but it' probably the other
extreme in the case of string formatting.
It's been expressed here quite a few times that compactness is also
desirable. By dividing it into two terms, you still get the compactness in
the most common cases and you get an easier to understand and read terms in
the more complex cases.
Or format fields dynamically by inserting components, it makes things a bit
easier.
BTW, the order of the grouping is flexible...
value_spec = "f.2"
"{0:{1},^30}".format(value, value_spec)
Or...
field_spec = "^30"
"{0:f.2,{1}}".format(value, field_spec)
So it breaks it up into logical parts as well.
Cheers,
Ron
More information about the Python-3000
mailing list