[Python-ideas] String formatting and namedtuple
spir
denis.spir at free.fr
Thu Feb 12 14:10:40 CET 2009
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
More information about the Python-ideas
mailing list