using generators with format strings

John Lenton jlenton at gmail.com
Tue Jul 27 09:23:31 EDT 2004


On Tue, 27 Jul 2004 09:15:57 -0400, Christopher T King <squirrel at wpi.edu> wrote:
> On Mon, 26 Jul 2004, Calvin Spealman wrote:
> 
> > 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 easily,
> > as you can see.
> 
> Not quite, because for the same reason as generators, lists are passed to
> % as a single argument.  The arguments must be contained in a tuple
> (tuple(myvalues()) does nicely).

does anyone else get the feeling that (str %) should have a third
behaviour wrt generators? By this I mean that str % seq is one
behaviour, str % dict is another, and there should be a str % iter,
probably consuming items from the iterator up to the number of
arguments of the format string?

-- 
John Lenton (jlenton at gmail.com) -- Random fortune:
bash: fortune: command not found



More information about the Python-list mailing list