Evaluation of variable as f-string
Chris Angelico
rosuav at gmail.com
Sat Jan 28 20:09:16 EST 2023
On Sun, 29 Jan 2023 at 11:56, Johannes Bauer <dfnsonfsduifb at gmx.de> wrote:
>
> Am 28.01.23 um 00:41 schrieb Chris Angelico:
> > On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
> > <python-list at python.org> wrote:
> >>
> >> Whoa! Whoa! Whoa!
> >> I appreciate the points you are making, Chris, but I am a bit taken
> >> aback by such forceful language.
> >
> > The exact same points have already been made, but not listened to.
> > Sometimes, forceful language is required in order to get people to
> > listen.
>
> An arrogant bully's rationale. Personally, I'm fine with it. I've been
> to Usenet for a long time, in which this way of "educating" people was
> considered normal. But I do think it creates a deterring, toxic
> environment and reflects back to you as a person negatively.
Arrogant bully? Or someone who has tried *multiple times* to explain
to you that what you're asking for is IMPOSSIBLE, and you need to ask
a better question if you want a better answer?
If that's "bullying", then fine, ban me for bullying, and go find
somewhere else where you'll be coddled and told that your question is
fine, it's awesome, and yes, wouldn't it be nice if magic were a
thing.
> Exactly. This is precisely what I want to avoid. Essentially, proper
> quotation of such a string requires to write a fully fledged f-string
> parser, in which case the whole problem solves itself.
>
> >>> Don't ask how to use X to do Y. Ask how to do Y.
> >> Good advice.
> >
> > Exactly. As I have shown, asking how to use f-strings to achieve this
> > is simply not suitable, and there's no useful way to discuss other
> > than to argue semantics. If we had a GOAL to discuss, we could find
> > much better options.
>
> I was not asking how to use f-strings. I was asking to evaluate a string
> *as if it were* an f-string. Those are two completely different things
> which you entirely ignored.
They're not different things, because what you asked for is NOT
POSSIBLE without the caveats that I gave. It is *fundamentally not
possible* to "evaluate a string as if it were an f-string", other than
by wrapping it in an f-string and evaluating it - with the
consequences of that.
> In other words, if there were a magic function:
>
> evalfstring(s, x = x)
>
> That would have been the ideal answer. There does not seem to be one,
> however. So I'm back to silly workarounds.
>
Right. Exactly. Now if you'd asked for what you REALLY need, maybe
there'd be a solution involving format_map, but no, you're so utterly
intransigent that you cannot adjust your question to fit reality.
If that makes me a bad guy, then fine. I'll be the bad guy.
But you're not going to change the laws of physics.
ChrisA
More information about the Python-list
mailing list