Is there a way to avoid having to escape literal curly brackets characters in a python3 f-string
?
For example if you want to output a json string or a chunk of CSS rules it's really inconvenient to have to convert all the {
and }
characters to {{
and }}
in case you want to use the f-string syntax.
I am aware that one can use the older syntax of e.g. div {color: %s} % color
, 'text {}'.format(abc)
or string templates but I wonder if there is a way to use the f-strings on raw text, preferably by having a way to mark the beginning and end of the 'raw' blocks with some kind of delimiter, for example similar to how you can use \Q
and \E
in a java regex in order to include unescaped raw characters in the regex.
As an alternative, is there something in the standard library that allows taking a chunk of raw text and converting it to an f-string-safe format? (again, similar to how you can use Pattern.quote for java regexes)