Re: python strings
Thu, 21 Apr 1994 11:48:03 +0200

I just noticed that Donald Beaudry's mod tries to support * specifiers
in a format as follows:

print '%(foobar).*f' % {'foobar': (5, 3.123456789)}

This would be equivalent to

print '%.*f' % (5, 3.123456789)

However with my proposed change of making %s (or %p) take ANY object
type, and with the order in which things are processed, this would
make it impossible to do things like

tup = (1, 2, 3)
print '%(tup)s' % {'tup': tup}

Therefore I propose to disable * specifiers in formats using

(The same problem could occur with non-dictionary formats, e.g.

print '%s' % tup

raises TypeError instead of printing str(t), but there it is more
easily corrected by using

print '%s' % str(tup)

while in the dictionary case (assuming vars() returns the local
variables) you would have to do silly things like

str_tup = str(tup)
print '%(str_tup)s' % vars()

PS there's one problem that vars() doesn't solve: suppose some of the
variables you want to print are locals and some are globals? There
really should be an inexpensive method to compute the "union" of two

--Guido van Rossum, CWI, Amsterdam <>
URL: <>