3

I am trying to format a text. Below is my code.

str = """
    def services = {0}
    try {
        // try code block
    } finally {
        // finally code block
    }
""".format(json.dumps(services))

But I am getting following error.

Key ' // try code block ' has no corresponding argument

Any help would be appreciated.

0

2 Answers 2

4

You need double curly braces around in the try catch part of the string as it is right now format is looking for extra arguments. Try try {{ }}.. so that the format will work properly.

Sign up to request clarification or add additional context in comments.

Comments

2

Try with {{}}. Like

try {{
   // try block her
}}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.