[Python-3000] String formating operations in python 3k

John J Lee jjl at pobox.com
Wed Apr 5 21:13:08 CEST 2006


On Wed, 5 Apr 2006, Greg Ewing wrote:
[...]
> There are other problems with the $ syntax too.
> The lack of an explicit closing marker causes
> problems when the parameter is immediately
> followed in the string by an alphanumeric
> character. You end up having to allow some
> kind of bracketing as an optional extra
> anyway, such as
>
>   subst("I'm a ${what}spotter", what = "train")
>
> Seems to me it's simpler as well as clearer
> to just make the syntax fully bracketed in the
> first place.

One argument against the plain {} syntax would be that, if you believe 
there should be one syntax that handles both simple substitution and 
formatting-with-format-characters nicely, you need somewhere to put the 
format characters.  Putting them at the end is problematic, as we know. 
But how about putting them at the start, after the $?  That way, the 
format character can't get mixed up with the text following it.  For 
example, $r{foo} would mean the same as the current %(foo)r.


John


More information about the Python-3000 mailing list