[Python-3000] Addition to PEP 3101

James Thiele python3now at gmail.com
Mon Apr 30 18:53:16 CEST 2007


For PEP: 3101  - Advanced String Formatting - I would like to suggest
the following additions.

First, that an additional pair of forms be added to format strings so
that callable objects could be used as parameters to the format string
method:
{0()} for positional arguments and
{keyword()} for keyword parameters.
The proposal is that if the format string had this form that the
format string method would treat the parameter as a callable and use
the value of the return for the formatting.

The second addition would be the forms
{0.method()} and
{keyword.method()}
where "method" is a method of the object.

This would allow things such as:
"I want to shout '{0.upper()}'".format("hello world")
which would yield:
 "I want to shout 'HELLO WORLD'"


More information about the Python-3000 mailing list