On Wed, 8 Feb 2023 at 05:30, Stefan Ram wrote:
>
> Rob Cliffe writes:
> >Does that mean that it is not possible to have a (built-in) function
> >that would construct and return a dictionary of all available variables
> >and their values? If it were possible, it could be useful, and there
> >woul
On Wed, 8 Feb 2023 at 02:12, Rob Cliffe wrote:
>
> [re-sending this to both the list and to Chris, as a prior send to the
> list only was bounced back]
> On 31/01/2023 22:33, Chris Angelico wrote:
> >
> >> Thanks for clarifying.
> >> Hm. So 'x' is neither in locals() nor in globals(). Which star
[re-sending this to both the list and to Chris, as a prior send to the
list only was bounced back]
On 31/01/2023 22:33, Chris Angelico wrote:
Thanks for clarifying.
Hm. So 'x' is neither in locals() nor in globals(). Which starts me
wondering (to go off on a tangent): Should there be a nonlo
On Wed, 1 Feb 2023 at 09:14, Rob Cliffe via Python-list
wrote:
> With great respect, Chris, isn't it for the OP (or anyone else) to
> decide - having been warned of the various drawbacks and limitations -
> to decide if it's a terrible idea *for him*? He's entitled to decide
> that it's just what
On 27/01/2023 23:41, Chris Angelico wrote:
On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
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.
On 2023-01-29 10:18:00 +0100, Johannes Bauer wrote:
> Am 29.01.23 um 05:27 schrieb Thomas Passin:
> > IOW, perhaps there is a more practical way to accomplish what you want.
> > Except that we don't know what that is.
>
> Well, I don't know. I pretty much want a generic Python mechanism that
> all
On 1/29/2023 6:09 AM, Christian Gollwitzer wrote:
Am 28.01.23 um 02:56 schrieb Thomas Passin:
On 1/27/2023 5:10 PM, Christian Gollwitzer wrote:
Am 27.01.23 um 21:43 schrieb Johannes Bauer:
I don't understand why you fully ignore literally the FIRST example
I gave in my original post and angril
Am 29.01.23 um 05:27 schrieb Thomas Passin:
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.
I'll have to accept the restrictions.
Am 28.01.23 um 02:56 schrieb Thomas Passin:
On 1/27/2023 5:10 PM, Christian Gollwitzer wrote:
Am 27.01.23 um 21:43 schrieb Johannes Bauer:
I don't understand why you fully ignore literally the FIRST example I
gave in my original post and angrily claim that you solution works
when it does not:
Am 29.01.23 um 02:09 schrieb Chris Angelico:
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
On 2023-01-29 15:47:47 +1100, Chris Angelico wrote:
> On Sun, 29 Jan 2023 at 14:36, Stefan Ram wrote:
> > (This message was written for Usenet. If you read it in a
> > mailing list or the Web, it has been stolen from Usenet.)
>
> I'm curious as to the copyright protections available to you, b
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 tryi
On Sun, 29 Jan 2023 at 14:36, Stefan Ram wrote:
>
> Johannes Bauer writes:
> >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.
>
> (This message was written
On Sun, 29 Jan 2023 at 11:56, Johannes Bauer wrote:
>
> Am 28.01.23 um 00:41 schrieb Chris Angelico:
> > On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
> > wrote:
> >>
> >> Whoa! Whoa! Whoa!
> >> I appreciate the points you are making, Chris, but I am a bit taken
> >> aback by such forc
On Sun, 29 Jan 2023 at 11:53, Johannes Bauer wrote:
> 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.
>
Not possible. An f-string can contain other f-strings, and it is
entirely possible to use
Am 27.01.23 um 23:10 schrieb Christian Gollwitzer:
Am 27.01.23 um 21:43 schrieb Johannes Bauer:
I don't understand why you fully ignore literally the FIRST example I
gave in my original post and angrily claim that you solution works
when it does not:
x = { "y": "z" }
s = "-> {x['y']}"
print(s
Am 28.01.23 um 00:41 schrieb Chris Angelico:
On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
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 t
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 y
On 2023-01-27 21:31:05 +0100, Johannes Bauer wrote:
> > But if you really REALLY know what you're doing, just use eval()
> > directly.
>
> I do, actually, but I hate it. Not because of the security issue, not
> because of namespaces, but because it does not reliably work:
>
> >>> s = "{\"x\" * 4}
On 2023-01-27 21:43:09 +0100, Johannes Bauer wrote:
> x = { "y": "z" }
> s = "-> {x['y']}"
> print(s.format(x = x))
> Traceback (most recent call last):
> File "", line 1, in
> KeyError: "'y'"
>
> This. Does. Not. Work.
>
> I want to pass a single variable as a dictionary and access its member
On 2023-01-27 20:56:49 -0500, Thomas Passin wrote:
> On 1/27/2023 5:10 PM, Christian Gollwitzer wrote:
> > Am 27.01.23 um 21:43 schrieb Johannes Bauer:
> > > x = { "y": "z" }
> > > s = "-> {x['y']}"
> > > print(s.format(x = x))
> > > Traceback (most recent call last):
> > > File "", line 1, in
-Original Message-
From: Python-list On
Behalf Of Stefan Ram
Sent: Friday, January 27, 2023 4:31 PM
To: python-list@python.org
Subject: Re: Evaluation of variable as f-string
Johannes Bauer writes:
>>Johannes Bauer writes:
>>>x = { "y": "z" }
>>>s =
On 1/27/2023 5:10 PM, Christian Gollwitzer wrote:
Am 27.01.23 um 21:43 schrieb Johannes Bauer:
I don't understand why you fully ignore literally the FIRST example I
gave in my original post and angrily claim that you solution works
when it does not:
x = { "y": "z" }
s = "-> {x['y']}"
print(s.
On 1/27/2023 3:33 PM, Johannes Bauer wrote:
Am 25.01.23 um 20:38 schrieb Thomas Passin:
x = { "y": "z" }
s = "-> {target}"
print(s.format(target = x['y']))
Stack overflow to the rescue:
No.
Search phrase: "python evaluate string as fstring"
https://stackoverflow.com/questions/47339121/h
Am 27.01.23 um 21:43 schrieb Johannes Bauer:
I don't understand why you fully ignore literally the FIRST example I
gave in my original post and angrily claim that you solution works when
it does not:
x = { "y": "z" }
s = "-> {x['y']}"
print(s.format(x = x))
Traceback (most recent call last):
Am 27.01.23 um 20:18 schrieb Chris Angelico:
All you tell us is
what you're attempting to do, which there is *no good way to achieve*.
Fair enough, that is the answer. It's not possible.
Perhaps someone will be inspired to write a function to do it. 😎
See, we don't know what "it" is, so it
Am 23.01.23 um 17:43 schrieb Stefan Ram:
Johannes Bauer writes:
x = { "y": "z" }
s = "-> {x['y']}"
print(s.format(x = x))
x = { "y": "z" }
def s( x ): return '-> ' + x[ 'y' ]
print( s( x = x ))
Except this is not at all what I asked for. The string "s" in my example
is just that, an exampl
Am 25.01.23 um 20:38 schrieb Thomas Passin:
x = { "y": "z" }
s = "-> {target}"
print(s.format(target = x['y']))
Stack overflow to the rescue:
No.
Search phrase: "python evaluate string as fstring"
https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string
de
Am 23.01.23 um 19:02 schrieb Chris Angelico:
This is supposedly for security reasons. However, when trying to emulate
this behavior that I wanted (and know the security implications of), my
solutions will tend to be less secure. Here is what I have been thinking
about:
If you really want the f
On 1/27/2023 5:54 PM, Rob Cliffe via Python-list wrote:
Whoa! Whoa! Whoa!
I appreciate the points you are making, Chris, but I am a bit taken
aback by such forceful language.
I generally agree with asking for what the intent is. In this case it
seems pretty clear that the OP wants to use the
On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
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 require
Whoa! Whoa! Whoa!
I appreciate the points you are making, Chris, but I am a bit taken
aback by such forceful language.
On 27/01/2023 19:18, Chris Angelico wrote:
On Sat, 28 Jan 2023 at 05:31, Rob Cliffe via Python-list
wrote:
On 23/01/2023 18:02, Chris Angelico wrote:
Maybe, rather than ask
On Sat, 28 Jan 2023 at 05:31, Rob Cliffe via Python-list
wrote:
> On 23/01/2023 18:02, Chris Angelico wrote:
> > Maybe, rather than asking for a way to treat a string as code, ask for
> > what you ACTUALLY need, and we can help?
> >
> > ChrisA
> Fair enough, Chris, but still ISTM that it is reason
On 23/01/2023 18:02, Chris Angelico wrote:
On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote:
Hi there,
is there an easy way to evaluate a string stored in a variable as if it
were an f-string at runtime?
...
This is supposedly for security reasons. However, when trying to emulate
this be
On 25/01/2023 19:38, Thomas Passin wrote:
Stack overflow to the rescue:
Search phrase: "python evaluate string as fstring"
https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string
def effify(non_f_str: str):
return eval(f'f"""{non_f_str}"""')
print(ef
On 1/25/2023 1:26 PM, Antoon Pardon wrote:
Op 23/01/2023 om 17:24 schreef Johannes Bauer:
Hi there,
is there an easy way to evaluate a string stored in a variable as if
it were an f-string at runtime?
I.e., what I want is to be able to do this:
x = { "y": "z" }
print(f"-> {x['y']}")
This p
Op 23/01/2023 om 17:24 schreef Johannes Bauer:
Hi there,
is there an easy way to evaluate a string stored in a variable as if
it were an f-string at runtime?
I.e., what I want is to be able to do this:
x = { "y": "z" }
print(f"-> {x['y']}")
This prints "-> z", as expected. But consider:
x
On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote:
>
> Hi there,
>
> is there an easy way to evaluate a string stored in a variable as if it
> were an f-string at runtime?
>
> ...
>
> This is supposedly for security reasons. However, when trying to emulate
> this behavior that I wanted (and know
Hi there,
is there an easy way to evaluate a string stored in a variable as if it
were an f-string at runtime?
I.e., what I want is to be able to do this:
x = { "y": "z" }
print(f"-> {x['y']}")
This prints "-> z", as expected. But consider:
x = { "y": "z" }
s = "-> {x['y']}"
print(s.format(
39 matches
Mail list logo