Message373305
Just change the f string quotes.
Python strings, whether f-strings or not, can be delimited by '' or "" or triple quotes. So this works:
>>> f"But, {'this quote is right.'}"
'But, this quote is right.'
Remember that the part of the f-string is evaluated as code, converted to a string, and interpolated into the rest of the f-string body. This is why the quotes disappear.
If you need both kinds of quotes, use triple-quotes as the delimiter:
>>> f"""Both {'single and "double" quotes'.title()}"""
'Both Single And "Double" Quotes'
I assume you want to pass the '' string to a function or something, and this example is just a simplified version. Because if there is no function call needed, you should just use a regular string, there's no need for an f-string:
"But, 'this quote is right.'" |
|
Date |
User |
Action |
Args |
2020-07-08 10:47:59 | steven.daprano | set | recipients:
+ steven.daprano, eric.smith, Nghia Minh |
2020-07-08 10:47:59 | steven.daprano | set | messageid: <1594205279.1.0.342310151747.issue41240@roundup.psfhosted.org> |
2020-07-08 10:47:59 | steven.daprano | link | issue41240 messages |
2020-07-08 10:47:59 | steven.daprano | create | |
|