Making string-formatting smarter by handling generators?
D'Arcy J.M. Cain
darcy at druid.net
Wed Feb 27 12:25:42 EST 2008
On Wed, 27 Feb 2008 10:23:49 -0600
Tim Chase <python.list at tim.thechases.com> wrote:
> I can force it by wrapping the results of my generator in a call
> to tuple() or list()
I think you are wrong about list(). Since map() returns a list already
it doesn't change anything.
> print "%s, %s" % tuple(map(transform, pair))
Yes, it works.
> but it feels a bit hackish to me.
I can't imagine what else you could do to turn a list into a tuple that
would be less hackish than simply making it a tuple.
> I find I hit it mostly with calls to map() where I want to apply
> some transform (as above) to all the items in a list of
> parameters such as
>
> "%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])
> Any suggestions? (even if it's just "get over your hangup with
> wrapping the results in list()/tuple()" :)
Pretty much. :-)
--
D'Arcy J.M. Cain <darcy at druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
More information about the Python-list
mailing list