Making string-formatting smarter by handling generators?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Feb 27 16:52:08 EST 2008


"D'Arcy J.M. Cain" <darcy at druid.net> writes:

> The above can be done with;
> 
>     "%s=%s&%s=%s" % tuple([urllib.quote(x) for x in params])

Or, better::

    "%s=%s&%s=%s" % tuple(urllib.quote(x) for x in params)

passing a generator, instead of a list created from a generator, to
the tuple constructor.

-- 
 \      "I put instant coffee in a microwave oven and almost went back |
  `\                                       in time."  -- Steven Wright |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list