7

I have a string in which i am using string formatting:

'SELECT {} FROM {} WHERE country={} AND \{\}'.format("apples", "tables","home")

Currently this doesnt work though; How to escape the { and } so that the string prints:

SELECT apples FROM tables WHERE country=home AND {}

?

jim jarnac
  • 4,804
  • 11
  • 51
  • 88

1 Answers1

21

You can escape the {} sequence by using {{}}:

>>> 'SELECT {} FROM {} WHERE country={} AND {{}}'.format("apples", "tables","home")
'SELECT apples FROM tables WHERE country=home AND {}'
Mureinik
  • 297,002
  • 52
  • 306
  • 350