[Python-3000] PEP 3101 Updated
Alex Holkner
aholkner at cs.rmit.edu.au
Thu Aug 16 05:17:50 CEST 2007
Talin wrote:
> A new version is up, incorporating material from the various discussions
> on this list:
>
> http://www.python.org/dev/peps/pep-3101/
I've been following this thread for a few weeks, and I believe the
following issues haven't yet been addressed:
The PEP abstract says this proposal will replace the '%' operator, yet
all the examples use the more verbose .format() method. Can a later
section in the PEP (perhaps "String Methods") confirm that '%' on string
is synonymous with the format method in Python 3000?
What is the behaviour of whitespace in a format specifier? e.g.
how much of the following is valid?
"{ foo . name : 20s }".format(foo=open('bar'))
One use-case might be to visually line up fields (in source) with a
minimum field width. Even if not permitted, I believe this should be
mentioned in the PEP.
Does a brace that does not begin a format specifier raise an exception
or get treated as character data? e.g.
"{@foo}"
or, if no whitespace is permitted:
"{ foo }"
or, an unmatched closing brace:
" } "
I don't have any preference on either behaviour, but would like to see
it clarified in the PEP.
Has there been any consideration for omitting the field name? The
behaviour would be the same as the current string interpolation:
"The {:s} sat on the {:s}".format('cat', 'mat')
IMO this has gives a nicer abbreviated form for the most common use case:
"Your name is {}.".format(name)
This has the benefit of having similar syntax to the default
interpolation for UNIX find and xargs commands, and eliminating errors
from giving the wrong field number (there have been several posts in
this thread erroneously using a 1-based index).
Apologies if I'm repeating answered questions.
Cheers
Alex.
More information about the Python-3000
mailing list