Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 237
Ram Avatar asked May 01 '26 16:05

Ram


1 Answers

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.

like image 70
Mitchell van Swol Avatar answered May 04 '26 04:05

Mitchell van Swol