Making string-formatting smarter by handling generators?
Arnaud Delobelle
arnodel at googlemail.com
Wed Feb 27 16:06:27 EST 2008
On Feb 27, 5:25 pm, "D'Arcy J.M. Cain" <da... at druid.net> wrote:
> On Wed, 27 Feb 2008 10:23:49 -0600
>
> Tim Chase <python.l... at tim.thechases.com> wrote:
>
> > "%s=%s&%s=%s" % map(urllib.quote, params)
>
> Isn't map() deprecated? The above can be done with;
>
> "%s=%s&%s=%s" % tuple([urllib.quote(x) for x in params])
I don't think that map() is deprecated. In python 3.0 it is still
present, only it returns an iterator instead of a list.
In this case
map(urllib.quote, params)
looks for urlib.quote exactly once altogether. Whereas
[urllib.quote(x) for x in params]
looks for urlib.quote once for every element in params. (Of course in
the example given params only has 4 elements so it doesn't matter).
--
Arnaud
More information about the Python-list
mailing list