handling curly braces in string formatting – python

let us say you want to print :

{text}

using

'{ {} }'.format(content)

how to escape the {}?

'\{ {} \}'.format(content)

works not

the answer

the answer is to double curly braces like that :

'{{ {} }}'.format(content)

simple !

  •  
  •  
  •  
  •  
  •  
  •  

Lives in Mauritius, cruising python waters for now.

Leave a Reply

Your email address will not be published. Required fields are marked *