10

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

?

2
  • Briefly: double them. Commented Jan 2, 2017 at 5:30
  • 1
    How about 'SELECT {} FROM {} WHERE country={} AND {}'.format("apples", "tables","home", "{}") ? Commented Jan 2, 2017 at 5:31

1 Answer 1

24

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

>>> 'SELECT {} FROM {} WHERE country={} AND {{}}'.format("apples", "tables","home")
'SELECT apples FROM tables WHERE country=home AND {}'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.