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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With