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,295
  • 12
  • 37
Andrej Vilenskij
  • 487
  • 1
  • 7
  • 23

1 Answers1

1

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

data = f"{{[{{{prod_id},{quantity},{size}}}]}}"
JohnO
  • 777
  • 6
  • 10