4 ms·
I love f-strings. Don't forget that you can do fr"some string {blah}" to build raw strings. >>> blah = "something \here" >>> fr"what the {blah}" 'what t
by lightlyused 6y ago
I love f-strings. Don't forget that you can do fr"some string {blah}" to build raw strings.
>>> blah = "something \here"
>>> fr"what the {blah}"
'what the something \\here'
- ghshephard 6y agoWhat version of python are you using. With python 3.8.5 1. \h doesn't get interpolated to anything (unlike \a, \b, \f, etc...) "\h" '\\h' "\a" '\x07' 2. The "r" needs to be in the original definition, not the f-string. blah = r"\a" You only need the "r" in the f-string if you don't want interpoolation of the "\" - I.e.: fr" this\a {blah}" 'This\\a \\a
- lightlyused 6y agoThis was just an example to show what it does, I normally wouldn't have \h in a string. I use this to store lists of regular expressions in aws dynamodb list type and to convert them back to raw strings when used.