1
formatter = "%r %r %r %r"
print formatter % (formatter, formatter, formatter, formatter) % ((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4))


Traceback (most recent call last):
  File "ex8.py", line 2, in <module>
    print formatter % (formatter, formatter, formatter, formatter) % ((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4))
TypeError: not enough arguments for format string

Is something wrong with my code? Or just can't do it.

1 Answer 1

1

You should use just one tuple for your formatting:

formatter = "%r %r %r %r"
print formatter % (formatter, formatter, formatter, formatter) % (1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)

If you want it to be more clear, you could do this:

formatter = "%r %r %r %r"
tuples = ((1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4), (1, 2, 3, 4))
print formatter % (formatter, formatter, formatter, formatter) % sum(tuples, ())

or better:

formatter = "%r %r %r %r"
tuples = (1, 2, 3, 4) * 4
print formatter % ((formatter,) * 4) % tuples
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.