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

Barry Warsaw barry at python.org
Mon Apr 3 14:00:15 CEST 2006


On Sun, 2006-04-02 at 23:26 -0500, Ian Bicking wrote:
> Georg Brandl wrote:
> > BTW, has anyone seen string.Template being used somewhere?
> 
> I use it from time to time, usually when formatting user-provided 
> strings (because "%(foo)s" is not very pleasant or easy-to-explain 
> compared to "$foo").  However, I *never* use it internally in code, 
> because the overhead of importing string and creating the template far 
> outweighs the inconvenience of %-based substitution.  Oh, and I really 
> like %r.

Good point.  Yes string.Template was designed primarily for i18n
applications for the reasons above, and because %(foo)s is more error
prone than necessary.

> I'd personally be very happy if $"$foo" worked, as well as 
> "$foo".substitute().  $/shell-style substitution is the norm out in the 
> world, not the %/printf style that Python uses; it'd be nice to move 
> towards that norm.  string.Template is a bit of a tease that way, since 
> it doesn't actually provide a very convenient alternative to the bulk of 
> what % is used for.

I don't much like the $"" prefix, but I agree that it would be nicer if
there were more direct support for $-strings.  OTOH, I don't see a good
way to marry the rich coercion of %-substitution with the simplicity of
$-substition.  I wouldn't want to lose that simplicity to gain that
richness in $-strings, so I suppose a prefix might be necessary.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060403/9338013d/attachment.pgp 


More information about the Python-3000 mailing list