[Python-ideas] String formatting and namedtuple
David Borowitz
ddborowitz at gmail.com
Thu Feb 12 19:29:15 CET 2009
Can't roughly the same thing be achieved with % substitution?
>>> msg = '%s == %s'
>>> print(msg % ('.format', 'improvement'))
.format == improvement
>>> msg % ('Python', 'greatness')
'Python == greatness'
The main non-syntactic difference here is that msg is a normal string object
rather than a bound method.
Not arguing against moving to .format, just that it doesn't seem inherently
more powerful than % in this case. (I guess you could still argue that this
pattern alleviates a concern with .format, namely repeated typing of
.format, but that's never been an issue with % to begin with.)
On Thu, Feb 12, 2009 at 05:10, spir <denis.spir at free.fr> wrote:
> Le Wed, 11 Feb 2009 20:06:37 -0500,
> Terry Reedy <tjreedy at udel.edu> a écrit :
>
> > One thing probably not mentioned in the PEP is the possibility of bound
> > methods, reduces typing of '.format' for reused formats.
> >
> > >>> msg = "{0} == {1}".format
> > >>> print(msg('.format', 'improvement'))
> > .format == improvement
> > >>> msg('Python', 'greatness')
> > 'Python == greatness'
>
> This is relevant. I've read the PEP and was not aware of such a wide open
> door. It allows building collections of string formats. Why not makes them
> public? Why not e.g. start a wiki page for common useful formats? Why not
> then store them into a standard module?
>
> I see loads of uses in the sole field of UI.
> "Please, enter a {0}."
> "Hello, {0}! Ausgeschlafen? Press enter to continue..." (slept well?)
> "name: {0} -- phone:{1} -- email{2}"
>
> Denis
> ------
> la vida e estranya
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
--
It is better to be quotable than to be honest.
-Tom Stoppard
Borowitz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090212/95422987/attachment.html>
More information about the Python-ideas
mailing list