-1

I just cannot to format of a string:

id = "3123123"
a = '{"classes": [], "field": {}}'.format(id)
print(a)

enter image description here

All suggestions will be nice !

4
  • 3
    a = '{{"classes": [], "field": {}}}'.format(id) Commented Apr 20, 2020 at 14:53
  • 1
    Put a 0 in between the curly braces to signal, that the first parameter in format() corresponds to the first index (0) in your string. If you want to use more than one variable you can increment this number like: a = 'Some{0} is {1}'.format('thing', 'weird') Edit: To escape curly braces in a format string, use double braces like @Shijith did Commented Apr 20, 2020 at 14:53
  • Or: a = f'{{"classes": [], "field": {id}}}' Commented Apr 20, 2020 at 14:58
  • Thanks a lot , all stuff was very useful ! Commented Apr 20, 2020 at 15:16

1 Answer 1

3

Your formatting string clashes with the formatting placeholder specifier

You'll need to escape the { with {{

a = '{{"classes": [], "field": {{}}}}'.format(id)

And a make sure there is a placeholder for id in the formatting string with {}

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot ! This was useful

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.