[Python-3000] PEP 3101 Updated

Talin talin at acm.org
Thu Aug 16 06:07:50 CEST 2007


Alex Holkner wrote:
> 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?

Well, originally it was my intent that the .format method would co-exist 
beside the '%' operator, but Guido appears to want to deprecate the '%' 
operator (it will continue to be supported until 3.1 at least however.)

> 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'))

Eric, it's your call :)

> 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 would say unmatched brace should not be considered an error, but I'm 
the permissive type.

> 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')

I suspect that this is something many people would like to move away 
from. Particularly in cases where different format strings are being 
used on the same data (a common example is localized strings), it's 
useful to be able to change around field order without changing the 
arguments to the function.

> 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.
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/talin%40acm.org
> 


More information about the Python-3000 mailing list