using generators with format strings

Terry Reedy tjreedy at
Tue Jul 27 01:17:16 CEST 2004

"Calvin Spealman" <calvin at> wrote in message
news:1177931.tnjPut6V3j at
> The generators are not list-type objects, but iterators. Because the %
> operator does not operate on iterators directly (because, presumably, you
> may be wanting to print the iterator itself, not the items it iterates
> over), you must construct a list out of it, which can be done very
> as you can see.
> x = "Hello, %s, this is a %s with %s and %s on top of %s" % [ i for i in
> myvalues()]
> y = "Yes it's true that %s has way too many %s's" % [i for i in

list(myvalues()) is even more concise and more direct than the list comp


More information about the Python-list mailing list