Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python escape "{}" symbol [duplicate]

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 {}

?

like image 475
jim jarnac Avatar asked Jan 02 '17 05:01

jim jarnac


1 Answers

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

>>> 'SELECT {} FROM {} WHERE country={} AND {{}}'.format("apples", "tables","home")
'SELECT apples FROM tables WHERE country=home AND {}'
like image 105
Mureinik Avatar answered Nov 04 '22 17:11

Mureinik