I am having problems using format with a string which looks like a Python dictionary.
I want to generate the following string: {"one":1}
If I try to do it as:
'{"one":{}}'.format(1)
the interpreter throws a KeyError:
>>> a = '{"one":{}}'.format(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: '"one"'
I understand that the issue probably revolves around the fact that the string contains {, which can be confused with format's {}. Why is this happening exactly and how can it be solved?
I know of percentage formatting, but I'd like to find a solution that doesn't involve ditching format().