[Python-3000] String formating operations in python 3k
Eric V. Smith
eric+python-dev at trueblade.com
Tue Apr 4 03:55:46 CEST 2006
> If I were designing a formatting system from scratch,
> I think I'd separate the issue of formatting numbers into
> strings from the issue of inserting strings into other
> strings. So instead of
>
> "Answer no. %5d is %8.3f" % (n, x)
>
> you would say something like
>
> subst("Answer no. {1} is {2}", format(i, 'd', 5), format(x, 'f', 8, 3))
Doesn't this violate Guido's "don't have a parameter that is always a
constant that changes how a function operates" principle (or whatever
its formal name is)? In this case, that's the type identifier 'd' or
'f'. I think format_int(i, 5) and format_float(x, 8, 3) would be
better. Or maybe a format() member of int and float, which take
different parameters. It's unlikely you'd need to specify the type
identifier at runtime.
But I agree with separating string insertion from number formatting.
You'd probably need to support locales with the number formatting.
Eric.
More information about the Python-3000
mailing list