
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@free.fr> wrote:
Le Wed, 11 Feb 2009 20:06:37 -0500, Terry Reedy <tjreedy@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@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- It is better to be quotable than to be honest. -Tom Stoppard Borowitz