Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curly braces with f-strings - ValueError: Sign not allowed in string format specifier [duplicate]

The following code:

a = 0
b = f'{"c": {a}}'

throws the error: ValueError: Sign not allowed in string format specifier How to fix it?

like image 663
petrush Avatar asked Dec 24 '18 17:12

petrush


1 Answers

Escape the braces like this.

>>> f'{{"c": {a}}}'
'{"c": 0}'
like image 50
cs95 Avatar answered Oct 02 '22 11:10

cs95