Evaluation of variable as f-string
Johannes Bauer
dfnsonfsduifb at gmx.de
Sat Jan 28 14:50:52 EST 2023
Am 28.01.23 um 02:51 schrieb Thomas Passin:
>> This is literally the version I described myself, except using triple
>> quotes. It only modifies the underlying problem, but doesn't solve it.
>
> Ok, so now we are in the territory of "Tell us what you are trying to
> accomplish". And part of that is why you cannot put some constraints on
> what your string fragments are. The example I gave, copied out of your
> earlier message, worked and now you are springing triple quotes on us.
It works in this particular case, yes. Just like the example I gave in
my original case:
eval("f'" + s + "'")
"works" if there are no apostrophes used. And just like
eval("f\"" + s + "\"")
"works" if there are no quotation marks used.
I don't want to have to care about what quotation is used inside the
string, as long as it could successfully evaluate using the f-string
grammar.
> Stop with the rock management already and explain (briefly if possible)
> what you are up to.
I have a string. I want to evaluate it as if it were an f-string. I.e.,
there *are* obviously restrictions that apply (namely, the syntax and
semantics of f-strings), but that's it.
Best,
Johannes
More information about the Python-list
mailing list