3

i want to use f-string in my python code to write some json, but got a problem with screening {} symbols. What the correct way to screen lonely { } symbols? For example i want to write:

data = f'{[{{prod_id},{quantity},{size}}]}'

I cant get how to write it correctly, and basic python screening not working for me for some reason here.

Granny Aching
  • 1,175
  • 7
  • 33
Andrej Vilenskij
  • 447
  • 1
  • 7
  • 20

1 Answers1

1

You can escape curly braces in f-strings by doubling them, e.g.

data = f"{{[{{{prod_id},{quantity},{size}}}]}}"
JohnO
  • 757
  • 5
  • 10