[Python-3000] String formating operations in python 3k
Crutcher Dunnavant
crutcher at gmail.com
Tue Apr 4 21:12:48 CEST 2006
On 4/3/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Barry Warsaw wrote:
>
> > I don't much like the $"" prefix
>
> This was discussed during the last round of formatting
> wars, and the conclusion was that having $ both
> inside and outside the string would be too visually
> confusing.
>
> > I don't see a good
> > way to marry the rich coercion of %-substitution with the simplicity of
> > $-substition.
>
> 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))
There are an awful lot of ways to say this, such as:
"Answer no. {1} is {2}".subst(int(i).format(5), float(x).format(8, 3))
Or:
"Answer no. {1} is {2}".subst(format(i, '5d'), format(x, '8.3f'))
Or:
"Answer no. {1} is {2}".subst(format('5d', i), format('8.3f', x))
Or:
"Answer no. {1} is {2}".subst(format('5d')(i), format('8.3f')(x))
> --
> Greg Ewing, Computer Science Dept, +--------------------------------------+
> University of Canterbury, | Carpe post meridiam! |
> Christchurch, New Zealand | (I'm not a morning person.) |
> greg.ewing at canterbury.ac.nz +--------------------------------------+
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/crutcher%40gmail.com
>
--
Crutcher Dunnavant <crutcher at gmail.com>
littlelanguages.com
monket.samedi-studios.com
More information about the Python-3000
mailing list