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

Barry Warsaw barry at python.org
Mon Apr 3 22:05:46 CEST 2006


On Mon, 2006-04-03 at 13:51 -0500, Ian Bicking wrote:

> > No it shouldn't be. format() should be a varargs function; __rmod__
> > takes a single argument which may be a tuple. Also, format() could
> > take keyword args in case the string contains named format, so I can
> > write e.g. "%(foo)s".format(foo=123).
> 
> Would "%(foo)s".format({'foo': 123}) work?  Or would you need **{...}?

I do think you'd want **{}.

> FWIW, I suspect I'd be much more likely to use named %'s with .format() 
> than with %; which is probably good, since named markers are more 
> flexible.  

Especially if .format() takes keywords as the substitution variables.

> E.g., I never do: "%(path)s: path %(path)r does not exist" % 
> {'path': path}, but I often do "%s: path %r does not exist" % (path, 
> path).  But the first form is really better in several ways.
> 
> If .substitute() (or .sub()?) was available to do $-based substitution 
> alongside .format() for %-based substitution, that would both have a 
> nice symmetry and make it more comfortable to move between the two.

It does feel that way.

-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/8a692fed/attachment.pgp 


More information about the Python-3000 mailing list