En Wed, 27 Feb 2008 14:23:49 -0200, Tim Chase <[EMAIL PROTECTED]> escribi�:
> Is there an easy way to make string-formatting smart enough to > gracefully handle iterators/generators? E.g. > > transform = lambda s: s.upper() > pair = ('hello', 'world') > print "%s, %s" % pair # works > print "%s, %s" % map(transform, pair) # fails > > with a """ > TypeError: not enough arguments for format string > """ Note that your problem has nothing to do with map itself. String interpolation using % requires either many individual arguments, or a single *tuple* argument. A list is printed as itself. py> "%s, %s" % ['hello', 'world'] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: not enough arguments for format string py> "%s" % ['hello', 'world'] "['hello', 'world']" So the answer is always use tuple(...) as others pointed. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list