New-style string formatting (Was: Re: Tuple "detection")
Ian Bicking
ianb at colorstudy.com
Tue May 20 19:55:18 EDT 2003
On Tue, 2003-05-20 at 14:11, Gerrit Holl wrote:
> Daniel Dittmar schreef op dinsdag 20 mei om 19:08:16 +0000:
> > > because the '%' is redundant; it's a much smaller change:
> >
> > redundant only for the common case of
> > "string %s %s" % (value1, value2)
> > but not for
> > "string %s %s" % db.getRow ()
>
> This would become:
>
> "string %s %s"(*db.getrow())
Maybe you would be happy with the idea of using * and ** prefixes in
literals (well, at least *), like:
(a, *b, c) == (a,) + tuple(b) + (c,)
And possibly:
{'a': b, **c}
meaning:
tmp = {'a': b}
tmp.update(c)
It still won't fix the problem of unintentially passing a tuple to %,
but maybe it would fix some of the problems.
Probably underlying this is that you like function call syntax (with
keywords, and *args/**kw) more than creating a literal. I agree -- it
is a more friendly syntax in the context of string substitution. But
maybe that can be better generalized with slightly richer literals.
Ian
More information about the Python-list
mailing list