I'm trying to use the str.format()
function to print a matrix in columns.
This is the line that goes wrong:
>>>> "{!s:4}{!s:5}".format('j',4,3)
'j 4 '
>>>> "{!s:4}{!s:5}".format(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> b
('dat', 'is')
What am I doing wrong?
Edit: I think I know what the problem is: I'm passing a tuple with two elements, which is than passed on to the function as a tuple with one element, my original tuple. Hence this error. so the question is rather how to pass this tuple to the format function...
{0}
, and that's what you get - the value ofb
."{0}, {1}".format(b)
fails (as does"{1}".format(b)
). This doesn't answer OP's question. – Sheik