Stupid string formatting question

Fernando Pérez fperez528 at yahoo.com
Thu May 16 23:22:08 EDT 2002


Michael S. Fischer wrote:

>> you just returned ("hi, "there", ("a", "b")) which is len(3) not 4.
> 
> OK.  What can I do to make this work?
> 

This is what doesn't work:

In [8]: print "%s/%s/%s/%s" % ("hi", "there", x())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

?

TypeError: not enough arguments for format string


But this does:

In [9]: print "%s/%s/%s/%s" % ( ("hi", "there")+ x())
hi/there/a/b


See the difference? you need to build  a _single_ list of 4 elements.

cheers,

f.



More information about the Python-list mailing list