Search code examples
pythonpython-2.7formattingstring-formatting

Unable to format a string


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.


Solution

  • Try with {{}}. Like

    try {{
       // try block her
    }}