> 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.
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com