Evaluation of variable as f-string

Thomas Passin list1 at tompassin.net
Sat Jan 28 23:27:58 EST 2023


On 1/28/2023 2:50 PM, Johannes Bauer wrote:
> 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.

Well, yes, we do see that.  What we don't see is what you want to 
accomplish by doing it, and why you don't seem willing to accept some 
restrictions on the string fragments so that they will evaluate correctly.

IOW, perhaps there is a more practical way to accomplish what you want. 
Except that we don't know what that is.



More information about the Python-list mailing list