Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Were there fewer fools, knaves would starve. -- Anonymous


devel / comp.lang.python / To gateway or not to gateway a specific person (was: Evaluation of variable as f-string)

SubjectAuthor
* Evaluation of variable as f-stringJohannes Bauer
+* Re: Evaluation of variable as f-stringStefan Ram
|+- Re: Evaluation of variable as f-stringStefan Ram
|`* Re: Evaluation of variable as f-stringJohannes Bauer
| `* Re: Evaluation of variable as f-stringStefan Ram
|  `- RE: Evaluation of variable as f-string<avi.e.gross
+* Re: Evaluation of variable as f-stringChris Angelico
|`* Re: Evaluation of variable as f-stringJohannes Bauer
| `- Re: Evaluation of variable as f-stringPeter J. Holzer
+- Re: Evaluation of variable as f-stringAntoon Pardon
+* Re: Evaluation of variable as f-stringThomas Passin
|`* Re: Evaluation of variable as f-stringJohannes Bauer
| `* Re: Evaluation of variable as f-stringThomas Passin
|  `* Re: Evaluation of variable as f-stringJohannes Bauer
|   +- Re: Evaluation of variable as f-stringChris Angelico
|   +* Re: Evaluation of variable as f-stringStefan Ram
|   |+- Re: Evaluation of variable as f-stringChris Angelico
|   |+- To gateway or not to gateway a specific person (was: Evaluation ofPeter J. Holzer
|   |`- Re: Evaluation of variable as f-stringStefan Ram
|   `* Re: Evaluation of variable as f-stringThomas Passin
|    `* Re: Evaluation of variable as f-stringJohannes Bauer
|     `- Re: Evaluation of variable as f-stringPeter J. Holzer
+- Re: Evaluation of variable as f-stringRob Cliffe
+- Re: Evaluation of variable as f-stringRob Cliffe
+* Re: Evaluation of variable as f-stringChris Angelico
|`* Re: Evaluation of variable as f-stringJohannes Bauer
| +* Re: Evaluation of variable as f-stringChristian Gollwitzer
| |+* Re: Evaluation of variable as f-stringThomas Passin
| ||`* Re: Evaluation of variable as f-stringChristian Gollwitzer
| || `- Re: Evaluation of variable as f-stringThomas Passin
| |+- Re: Evaluation of variable as f-stringPeter J. Holzer
| |`- Re: Evaluation of variable as f-stringJohannes Bauer
| `- Re: Evaluation of variable as f-stringPeter J. Holzer
+- Re: Evaluation of variable as f-stringRob Cliffe
+* Re: Evaluation of variable as f-stringChris Angelico
|`* Re: Evaluation of variable as f-stringJohannes Bauer
| `* Re: Evaluation of variable as f-stringChris Angelico
|  `- Re: Evaluation of variable as f-stringJohannes Bauer
+- Re: Evaluation of variable as f-stringThomas Passin
+- Re: Evaluation of variable as f-stringRob Cliffe
+* Re: Evaluation of variable as f-stringChris Angelico
|`- Re: Evaluation of variable as f-stringJohannes Bauer
+* Re: Evaluation of variable as f-stringRob Cliffe
|`* Re: Evaluation of variable as f-stringStefan Ram
| `- Re: Evaluation of variable as f-stringChris Angelico
`- Re: Evaluation of variable as f-stringChris Angelico

Pages:12
Re: Evaluation of variable as f-string

<tr3un3$2buff$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21430&group=comp.lang.python#21430

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dfnsonfs...@gmx.de (Johannes Bauer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sat, 28 Jan 2023 20:57:23 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <tr3un3$2buff$2@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<mailman.1677.1674862913.20444.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 28 Jan 2023 19:57:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="de874888c2d413a4e82c8a3694ab67ff";
logging-data="2488815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JVISP87bteyGkkvrp1h4ybsg9oPLN7MA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:lqVlIvDKvJOE6C2C/+Mk9cVRpnI=
In-Reply-To: <mailman.1677.1674862913.20444.python-list@python.org>
Content-Language: en-US
 by: Johannes Bauer - Sat, 28 Jan 2023 19:57 UTC

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@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.

>> Addressing your points specifically:
>> 1) I believe the quote character limitation could be overcome. It
>> would need a fair amount of work, for which I haven't (yet) the time or
>> inclination.
>
> No problem. Here, solve it for this string:
>
> eval_me = ' f"""{f\'\'\'{f"{f\'{1+2}\'}"}\'\'\'}""" '
>
> F-strings can be nested, remember.

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.

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.

Cheers,
Johannes

Re: Evaluation of variable as f-string

<tr3uvr$2buff$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21431&group=comp.lang.python#21431

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dfnsonfs...@gmx.de (Johannes Bauer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sat, 28 Jan 2023 21:02:03 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <tr3uvr$2buff$3@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<mailman.1669.1674849042.20444.python-list@python.org>
<tr1d0t$1r96f$4@dont-email.me> <tr1i5c$1saqj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 28 Jan 2023 20:02:03 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="de874888c2d413a4e82c8a3694ab67ff";
logging-data="2488815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198zWNzTasOI2tuP0QoiPDkCfjbUb2AMBw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:m8YSU8n1DNxB72ORuxJ2WM7ErQA=
Content-Language: en-US
In-Reply-To: <tr1i5c$1saqj$1@dont-email.me>
 by: Johannes Bauer - Sat, 28 Jan 2023 20:02 UTC

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.format(x = x))
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> KeyError: "'y'"
>>
>> This. Does. Not. Work.
>
> It's because "you're holding it wrong!". Notice the error message; it
> says that the key 'y' does not exist.

Ah, that is neat! I didn't know that. Thanks for the info.

In my case, I do also however want to have some functionality that
actually does math or even calls functions. That would be possible with
templates or f-strings, but not format:

x = { "t": 12345 }
s = "{x['t'] // 60:02d}:{x['t'] % 60:02d}"
print(s.format(x = x))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: "'t'"

and

s = "{x[t] // 60:02d}:{x[t] % 60:02d}"
print(s.format(x = x))

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Only '.' or '[' may follow ']' in format field specifier

but of course:

print(f"{x['t'] // 60:02d}:{x['t'] % 60:02d}")
205:45

Best,
Johannes

Re: Evaluation of variable as f-string

<mailman.1697.1674954365.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21439&group=comp.lang.python#21439

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 12:05:51 +1100
Lines: 14
Message-ID: <mailman.1697.1674954365.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<CAPTjJmpYpN9ccNEgy3ZiQpjm80QaYXTO_ZzztYMcSwE2VcocZg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 03lQxMANPW+zVEu5TlLTOQKAqajmWOqk2qwLKZvDJcEg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=q2JNFucW;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.043
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; '2023': 0.07; 'string':
0.07; 'sun,': 0.07; 'string,': 0.09; 'chrisa': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'received:209.85.218': 0.16; 'subject:string': 0.16;
'subject:variable': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'version': 0.23; 'python,': 0.25; "doesn't": 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'currently': 0.37; 'using': 0.37; "it's": 0.37; 'received:209.85':
0.37; 'could': 0.38; 'received:209': 0.39; 'use': 0.39; 'want':
0.40; 'outside': 0.67; 'care': 0.71; 'future': 0.72; 'quote':
0.74; '(that': 0.84; 'quotation': 0.84; 'quotes': 0.84; 'type.':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=LrIfgXRSNvw/H+2b5WvNabFT+yivho+lWGYbDU8amWY=;
b=q2JNFucWnv9j50KUw3IcERy5LMjjdzhIUxyBHttlkWtUv/lWAZzAqBSMz9gPkj3ltz
V6wPSZDWGd9SqiQVtr43dhJnoeW3NGhDHHCUd+gRbJQa0Kyhf7Ax45sCsm/UwlnK2IyT
TD8S4RHnokdZyOzKCekaw73UqaH7ulJs7lFufSOOU5Zx86Yz6aVQpvPTFkrS3e3RIfI7
HS7xg92nmLuCM7sZ7oOChn8vWPoCllV7m6lNdBzMHZgDQ/boCWTmldP5WExfrmY+q48x
HsfkN8jY/OS0WcXtZ38SXcroJaHsKso/DhNKIWmn/5JFrqnRSH2zE5CkxGuaj6Ow3Klk
nJZg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=LrIfgXRSNvw/H+2b5WvNabFT+yivho+lWGYbDU8amWY=;
b=ay4ymWvh0usO4fvMCeZlbxC3GPitWt2cMJ+q8sxZmOr6DDzR31ZdymsCo5/qnkUA3Q
IlDsC1TFxNSI6Jiq0dCliKPzgE+M61LbamUabYVi5FwAVNqr4+bItzJof3G1ZSoz3OOf
6opbfGllMzJ+OB6rAoIy21zVtuY9BI2WUFfRWmG5Q47G2UbSehjK2PVWS1+WLT76sCAE
DFDnxoren9o0gN/FDNttOfCgqBWfM/dwgQWyNyDkTg+9cwGo3myMynhwB0K7w2CT160+
pewizr6WiEMg3gIWOKy7PU+SAT4WKCKold4xedYUziYqzfxm0AXnazS/hgAOWo7ybgOq
WI5g==
X-Gm-Message-State: AO0yUKUnkF5tXNAK+Ev7swbBDiDOi0f3SGnXz46qa/Ffy9MRQMkw2Il2
Lqa3n738kU+3M8TTagojF+A+D6FBjDz0quBVk9xRSmw3
X-Google-Smtp-Source: AK7set+fFLupHO785Ri1mc+Lz3JbFTokreUDoawHIF5XNdirar+xlQPppm6rCMaOhTetG1MkrGf5zkdwhNOzUC6Ax9g=
X-Received: by 2002:a17:906:6d07:b0:878:67ab:4fa4 with SMTP id
m7-20020a1709066d0700b0087867ab4fa4mr2959635ejr.28.1674954363590; Sat, 28 Jan
2023 17:06:03 -0800 (PST)
In-Reply-To: <tr3uas$2buff$1@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpYpN9ccNEgy3ZiQpjm80QaYXTO_ZzztYMcSwE2VcocZg@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
 by: Chris Angelico - Sun, 29 Jan 2023 01:05 UTC

On Sun, 29 Jan 2023 at 11:53, Johannes Bauer <dfnsonfsduifb@gmx.de> 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 EVERY quote type. So you can never add quotes
around the outside of a string and then evaluate it as an f-string,
without making sure that it doesn't already contain that string.

(That MAY be changing in a future version of Python, but it's currently true.)

ChrisA

Re: Evaluation of variable as f-string

<mailman.1698.1674954569.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21440&group=comp.lang.python#21440

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 12:09:16 +1100
Lines: 67
Message-ID: <mailman.1698.1674954569.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<mailman.1677.1674862913.20444.python-list@python.org>
<tr3un3$2buff$2@dont-email.me>
<CAPTjJmrniYsWe2Za97s+W9-B6tn9ZqUL3ZkPvTXr_qvWgPuPJg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de hzMjmcULv8dRTt50YNNT9gTbotmYzY24sXM0o9U7tGXw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=bvZmMR7t;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.018
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '2023': 0.07; 'string':
0.07; 'sun,': 0.07; 'thing.': 0.07; 'schrieb': 0.09; 'sometimes,':
0.09; 'that.': 0.15; 'answer.': 0.16; 'chrisa': 0.16;
'evaluating': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'ignored.': 0.16; 'involving': 0.16;
'personally,': 0.16; 'rationale.': 0.16; 'reality.': 0.16;
'received:209.85.218': 0.16; 'right.': 0.16; 'solves': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'things,': 0.16;
'wrote:': 0.16; 'problem': 0.16; 'to:addr:python-list': 0.20;
'language': 0.21; "i've": 0.22; 'creates': 0.22; 'maybe': 0.22;
'sat,': 0.22; 'goal': 0.23; 'cannot': 0.25; 'tried': 0.26; 'else':
0.27; 'bit': 0.27; '>>>': 0.28; 'chris': 0.28; 'environment':
0.29; 'asked': 0.29; 'whole': 0.30; 'seem': 0.31; 'think': 0.32;
'question': 0.32; 'fine.': 0.32; 'language.': 0.32; 'python-list':
0.32; 'words,': 0.32; "wouldn't": 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33; "i'll": 0.33;
'there': 0.33; 'someone': 0.34; 'same': 0.34; 'requires': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'fine':
0.35; 'yes,': 0.35; 'from:addr:gmail.com': 0.35; 'people': 0.36;
'change': 0.36; 'those': 0.36; 'really': 0.37; "it's": 0.37;
'received:209.85': 0.37; 'way': 0.38; 'could': 0.38;
'received:209': 0.39; 'two': 0.39; 'use': 0.39; 'to.': 0.39;
'exact': 0.40; 'explain': 0.40; 'want': 0.40; "there's": 0.61;
'simply': 0.63; "you'd": 0.64; 'your': 0.64; 'required': 0.65;
'back': 0.67; 'bad': 0.67; 'time,': 0.67; 'order': 0.69; 'skip:*
10': 0.71; "you'll": 0.73; 'need,': 0.76; 'discuss': 0.78;
'points': 0.84; 'consequences': 0.84; 'exactly.': 0.84; 'guy,':
0.84; 'itself.': 0.84; 'made,': 0.84; 'quotation': 0.84; 'rob':
0.84; 'magic': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=XI56Y59wAnAyYOnil+XZq+of/i493MoBYr1EE7URyec=;
b=bvZmMR7t6/iw/5LgLuF7Q0UYFxGggBXyww8p++hB3UJznfllBaU7Q+2Dxxj7+SpX2N
sOL7xseQVioHjWGBfqT3PqNAJ7FZzi6JaMN/zSgdheFw1nOf/7b8A60NbuMQAOoDIqPE
MMUE6bcH0d4yKawoTCkF8AT7Rhdz1FJjvWm6YLjfgHDKgg+LZtNU/5IqItMYxhQYEUic
BtbEPBZPvBmZVaz7sqWxbG9Xo/8av0XPO23qrPVFa853Pl3MYzmJioAhLyfDbfcZIHM8
X5QQu3q8n32sk+qAEhLNhVn+I6+dgqjUcoY0xgilYXeZ3jgyelqp/uMjkFTSoUUNS/iW
tWrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=XI56Y59wAnAyYOnil+XZq+of/i493MoBYr1EE7URyec=;
b=Lb2VZZPSPYPhqKIIAsPgRhrrP5cAMk42aawaStM+gCOY0ebvPocVrsEwP+nZ14jCEQ
xPUNcznduhyFO0AiOFrga5A3Zkp/7kwD/s8QECXwMRWg/qZpl4Lo9PcMJfArcZetkrQC
lQtb/yQ4zQeSFVyzVEM+bZeepNcQP0iIRdURF9GPJbz3beqoNjcDjzc3Xdzh8MRr07rm
YQfxCkW7euC8ridOcvdUOWaBilNF+ZV3gSofv/PIga9LpQ+NwMkOz4Lg6u5uYmKzOt3d
y/XY7y7Fb9/LDHYsmSsLK8X1umW/EyrfzCTLMpXfsPHzalTgulj+y6U+D2Rl7zoQ9j/Z
z4Rw==
X-Gm-Message-State: AO0yUKU4XB12kgfYx2cyDY9ZnkoBrhnNJ7nktKzn9o5VyNo1eVRs9pcg
0KmAFPf3SfbXYWdX5JBtfJGjPwHaAminL6cCJZJfoK/t
X-Google-Smtp-Source: AK7set+CCEIoJb0VaQA8TzUjtJoj9w8zi9XQ3WNn+ksdioBXtT0b1+aVbrV+QXElyX8gIf1nyQuYUMmfmtIJWz2s93g=
X-Received: by 2002:a17:907:20a3:b0:885:5d1d:e33d with SMTP id
pw3-20020a17090720a300b008855d1de33dmr366277ejb.108.1674954567738; Sat, 28
Jan 2023 17:09:27 -0800 (PST)
In-Reply-To: <tr3un3$2buff$2@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrniYsWe2Za97s+W9-B6tn9ZqUL3ZkPvTXr_qvWgPuPJg@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<mailman.1677.1674862913.20444.python-list@python.org>
<tr3un3$2buff$2@dont-email.me>
 by: Chris Angelico - Sun, 29 Jan 2023 01:09 UTC

On Sun, 29 Jan 2023 at 11:56, Johannes Bauer <dfnsonfsduifb@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@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

Re: Evaluation of variable as f-string

<f-20230129031404@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21448&group=comp.lang.python#21448

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: 29 Jan 2023 02:18:43 GMT
Organization: Stefan Ram
Lines: 44
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <f-20230129031404@ram.dialup.fu-berlin.de>
References: <tqmcbf$vdl$1@gioia.aioe.org> <d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be> <5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net> <mailman.1613.1674675531.20444.python-list@python.org> <tr1ces$1r96f$3@dont-email.me> <9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net> <mailman.1683.1674870701.20444.python-list@python.org> <tr3uas$2buff$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de A2CsmYYHSyk2w4TXq6m8jAq2MGUUzC2LZLd6L6HfVRl4EJ
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sun, 29 Jan 2023 02:18 UTC

Johannes Bauer <dfnsonfsduifb@gmx.de> 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 for Usenet. If you read it in a
mailing list or the Web, it has been stolen from Usenet.)

So, you want your run-time client or run-time user to have the
same choices as someone who is just writing python source code
and is using an f-string?

Then what about,

name = input( 'name of the dictionary? ' )
s = input( 'string? ' )
dictionary = eval( input( 'dictionary? ' ))
print( eval( s, {name:dictionary} ))

? Here are four transcripts:

name of the dictionary? x
string? f"-> {x['y']}"
dictionary? { "y": "z" }
-> z

name of the dictionary? x
string? f'-> {x["y"]}'
dictionary? { "y": "z" }
-> z

name of the dictionary? x
string? f"-> {x['''y''']}"
dictionary? { "y": "z" }
-> z

name of the dictionary? x
string? f'-> {x["""y"""]}'
dictionary? { "y": "z" }
-> z

.

Re: Evaluation of variable as f-string

<mailman.1701.1674967681.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21453&group=comp.lang.python#21453

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 15:47:47 +1100
Lines: 20
Message-ID: <mailman.1701.1674967681.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<f-20230129031404@ram.dialup.fu-berlin.de>
<CAPTjJmo8qoq3ZbHoEKkFnrZiQHZb7vZRPRjHH7G-C2T4EaRNYA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de pW/KX0VDUsl0OKUvDGUyIwvZEA2CJ+OgxE9+gpBJq98w==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=PSRcxd+2;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'restrictions': 0.05;
'2023': 0.07; 'ram': 0.07; 'sun,': 0.07; 'obviously': 0.09;
'writes:': 0.09; 'syntax': 0.15; 'banned': 0.16; 'chrisa': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'i.e.,': 0.16; 'liability.': 0.16; 'received:209.85.218': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'them?': 0.16;
'wrote:': 0.16; 'reduce': 0.19; 'to:addr:python-list': 0.20;
'written': 0.22; "what's": 0.22; 'stefan': 0.26; '(this': 0.32;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33;
'mailing': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'lists':
0.37; 'received:209.85': 0.37; 'read': 0.38; 'received:209': 0.39;
'list': 0.39; 'want': 0.40; 'seen': 0.62; 'public': 0.63;
'owners': 0.64; 'your': 0.64; 'bad': 0.67; 'order': 0.69;
'copyright': 0.84; 'stolen': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=/WMcryNmp1ddHyehiGmw3LZbjCoUCF+Gl9BewZx00MA=;
b=PSRcxd+2ntDrWiA6cwu70cXeiIabQurderPtP6MLUlOmVL/Hpg1+xyY42gUx7EJ3nn
9mLjitxi1JakrxfUzP1mqf679mjLJUSEBIGCFOnZpbdT8oOTd6zl1Rc/o6hdUM4tx2Er
RyNguKzGG1APw6YkJ4+KzNZQcA45XGCy7aqojPCpIwzJXvJ56DjeWSr+xV1qlCOfx8QL
TSP+n1CL8OhZ2AB62Ff9UufJHd2WsCuCgyqw7IcykI0QnNFI3zmrE3kjzlWSAW1ri/U7
hcOHKMXyvHXQkrUKgWf74CYYhqdNU0XreBP3sVBkL14SgOTJsflCqEjSPgPx9vuy+mBB
kvLw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=/WMcryNmp1ddHyehiGmw3LZbjCoUCF+Gl9BewZx00MA=;
b=vGrMUx8b/kloNbARZ4pqNAwvMNx+vuBLUkPXyf0Wh9/KQWD0HTlp5/qYE0CubIIlm9
nt8JTciEezrRGAW0420ACD7aNUAxOW6kI4JEh+T8xa3wx1fonKlmKRQnFDm9OY1M6EA+
3v5/jSD6B9p6GE6u2Lr5w2/JTXiIzLbubR87g2NBqIHkl57GZzXpbUYly53fRUOdz8BL
Npj9bJ7W/SGSCHQ6n3Ca+ilGUa0Mj2Dk7ce2XoN/yprLYOk6sQQ/mXJUUxig9SPPxgTZ
WNOnzVsn7wb3s2cP+I0Rfx59jsElej6gFbH68qyPrbxcsRkTC1BXy1dIBrPlMRMJXlUm
8yxg==
X-Gm-Message-State: AO0yUKWLyObTGFzDOGd/xCtWiz2njteQCxPPvrKPPjbYfIOK8XDx7gbk
ITf3XLwIvOl7agH/DFbMEVzxIDYcQ7fJNd3BSv4H1yDJ
X-Google-Smtp-Source: AK7set88eWtBYAL6ZYBSgXUnVm8vwyOGkMtAwKFlqGEAJnZJ+Dv2Z2cyBY1ZvkxuucDbagAPgPQ0mZ8OWA2IATl2V/I=
X-Received: by 2002:a17:906:2287:b0:880:575f:b20c with SMTP id
p7-20020a170906228700b00880575fb20cmr1058153eja.177.1674967678397; Sat, 28
Jan 2023 20:47:58 -0800 (PST)
In-Reply-To: <f-20230129031404@ram.dialup.fu-berlin.de>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmo8qoq3ZbHoEKkFnrZiQHZb7vZRPRjHH7G-C2T4EaRNYA@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<f-20230129031404@ram.dialup.fu-berlin.de>
 by: Chris Angelico - Sun, 29 Jan 2023 04:47 UTC

On Sun, 29 Jan 2023 at 14:36, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>
> Johannes Bauer <dfnsonfsduifb@gmx.de> 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 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, but if
you're going to threaten python-list's owners with legal action for
daring to rebroadcast a public post, I would have to recommend that
you get promptly banned from the list in order to reduce liability.

What's so bad about mailing lists that you don't want your messages to
be seen on them?

ChrisA

Re: Evaluation of variable as f-string

<mailman.1703.1674968790.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21455&group=comp.lang.python#21455

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sat, 28 Jan 2023 23:27:58 -0500
Lines: 41
Message-ID: <mailman.1703.1674968790.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<8ca25af2-8a5b-b915-4706-da1398d56d24@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de /VVwo9mGGT6SrQ+SD26p5ARXgtLnhRJStZ4PsvuW7aSA==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=lARinB4F;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'is.': 0.05;
'restrictions': 0.05; 'string': 0.07; 'underlying': 0.07; 'used.':
0.07; 'obviously': 0.09; 'ok,': 0.09; 'schrieb': 0.09; 'string,':
0.09; 'yes.': 0.09; 'syntax': 0.15; 'that.': 0.15; 'are.\xc2\xa0':
0.16; 'case:': 0.16; 'i.e.,': 0.16; 'marks': 0.16; 'modifies':
0.16; 'quotes.': 0.16; 'received:10.0.0': 0.16; 'received:64.90':
0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'semantics': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16;
'solve': 0.19; 'pm,': 0.19; 'to:addr:python-list': 0.20;
'problem,': 0.22; 'version': 0.23; 'cannot': 0.25; '>>>': 0.28;
'it,': 0.29; 'header:User-Agent:1': 0.30; 'seem': 0.31; "doesn't":
0.32; 'accomplish': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'there':
0.33; 'particular': 0.33; 'header:In-Reply-To:1': 0.34; 'trying':
0.35; 'yes,': 0.35; 'using': 0.37; 'way': 0.38; 'could': 0.38;
'put': 0.38; 'to.': 0.39; 'explain': 0.40; 'want': 0.40; 'gave':
0.61; 'willing': 0.64; 'your': 0.64; 'earlier': 0.67; 'worked':
0.67; 'accept': 0.67; 'header:Received:6': 0.67; 'received:64':
0.67; 'management': 0.68; 'care': 0.71; 'practical': 0.84; '2:50':
0.84; 'constraints': 0.84; 'literally': 0.84; 'quotation': 0.84;
'quotes': 0.84; 'territory': 0.84; 'want.': 0.84
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1674966479; a=rsa-sha256;
cv=none;
b=vnqMmCV/NnLct/8ValJbHguIcsj1jZNyJ2si5LETQUrunilF0Fi8DOLZr7xELr1QGZDWA3
lqmVf8rOl+qsdSWusbNH5G7QCwKPBoN+C7yl9L6zxLaBOgwFdXAPeYySmW1vju6VdaoNp+
HTnrqVP69AwWv3SVCPS5m8bjA7AdPtqVDPxwP/ahmmeJuQCOnnqhnVBcrIqTZBchMlPmod
SgwJDliDm+rN1JOST99mloADk/IlVjTaiC7eOBjkSNyFB+Vs3/Lrrq1FcjJy1rAMDXdNJ7
Goh2LzK3fi2Up7nc6h6Tv1QbAaS0XwYoBXmqlfmX7mC2h0p3fNuv32gGJijQ4g==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1674966479;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=wTPjey/5uPJ29g5RIbBUTRLGEmX7wa1SYXS8lklmuGo=;
b=LWMDTThc/0IUZhg0j60O29ks650CDqgLvA/BWlL9mgXE0xxDCB1PkmS7t5lesacGkuH1Cv
9FUJpKHdXW3XifgHINqylANJrMgNOAYnJw4OD+H0RZv6lxvj3LfOZAbX8EOWgMR85Exz5I
2F4lFDz4Glf2jEDafk3Gx6+c0aIDWyRQegwqg8UWAKdtnhlJlUM/BPQ7ci/EDvLsfHMm/8
2y5tuqUpaAAwpEKzIacryHarrVeFYoC86TvjM4zAvmRgB6+AEeFGGM9SFZd/4g9oLRFbhk
nnqM+Ow6TJwfkya813PkyKf43O+7LSHG4YogJDeVwzbIw0aOQniE99RFH5UEDA==
ARC-Authentication-Results: i=1; rspamd-5fb8f68d88-58h5x;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Sponge-Stupid: 150c314e6acc2cf0_1674966479426_739359681
X-MC-Loop-Signature: 1674966479426:3010618019
X-MC-Ingress-Time: 1674966479426
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1674966479;
bh=wTPjey/5uPJ29g5RIbBUTRLGEmX7wa1SYXS8lklmuGo=;
h=Date:From:Subject:To:Content-Type:Content-Transfer-Encoding;
b=lARinB4FteNgK3ac01OLl18A6a+/1FHPxxeC2mwTEkxpxXFoXeOfnzhYDRKMTnvIj
L33+Hdrgg72H8wa76KN7EqVncROubuGfrFtJH27U+O+1xQEHuXBy9z0wK58siEX3fe
pwEF1vNz6jyNRDqL6SFx2FerdXSQbXfKNbOGCMAr5cO2m+Xr/iaZD+U+W6fPfMn/cQ
d+s9NrHK0Ady92bLOGNHZ6Zk7TE/S3KIvhxA21rQrOi9fa9CFRlooeh4jqAd8Sr0c8
VO+2i4ETVqxltYIvllbJC9pBFMBqNiIRlM7Y+0b5QjrWcFtaLJpLDsxZ17nkOUNu7v
Wnz6goBADKvVA==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <tr3uas$2buff$1@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <8ca25af2-8a5b-b915-4706-da1398d56d24@tompassin.net>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
 by: Thomas Passin - Sun, 29 Jan 2023 04:27 UTC

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.

Re: Evaluation of variable as f-string

<tr5css$2mlid$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21458&group=comp.lang.python#21458

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dfnsonfs...@gmx.de (Johannes Bauer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 10:05:31 +0100
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <tr5css$2mlid$1@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<mailman.1677.1674862913.20444.python-list@python.org>
<tr3un3$2buff$2@dont-email.me>
<CAPTjJmrniYsWe2Za97s+W9-B6tn9ZqUL3ZkPvTXr_qvWgPuPJg@mail.gmail.com>
<mailman.1698.1674954569.20444.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 29 Jan 2023 09:05:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="1b04e274401c7c621fe2d51272691b37";
logging-data="2840141"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rJ3+ULUB92LX/0qb+cESgyHEU0iXsk88="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:KvThpAGirN6J3xDI7iJCsWB7y9s=
Content-Language: en-US
In-Reply-To: <mailman.1698.1674954569.20444.python-list@python.org>
 by: Johannes Bauer - Sun, 29 Jan 2023 09:05 UTC

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 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?

In literally your first answer you resorted to aggressive language and
implied that what I asked wasn't what I actually wanted. It was.

Also note that in your first answer you did not answer "sorry, this is
not possible", which would have been completely sufficient as an answer.
Instead you tried your best at guesswork, implying I didn't know what I
was doing.

So, yes, absolutely toxic behavior. I fully stand by that judgement of mine.

I'll go a step further and again repeat that THIS sort of behavior is
what gives open source forums a bad rep. There's always a Lennart
Poettering, an Ulrich Drepper or maybe a Chris Angelico around who may
have great technical skill but think they can treat people like shit.

> 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.

LOL, "ban you"? What the heck are you talking about, my friend?

I don't need to be coddled by you. I'm trying to give you the favor of
honest feedback, which is that you sound like an utter bully. If you
don't care, that is totally fine by me.

> 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.

Yeah that sucks, unfortunately. But I'll live.

>> 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.

Does format_map do exactly what f-strings can do? Can I pass arbitrary
functions and Python expressions insode a format_map? No? Of course not.
Then it does not answer the question.

> If that makes me a bad guy, then fine. I'll be the bad guy.

Awww, it's adorable how you're trying to frame yourself as the victim.
I'll be here if you need a hug, buddy.

> But you're not going to change the laws of physics.

Yeah we'll have to disagree about the fact that it's the "laws of
physics" preventing a specific implementation of a Python function.

Cheers,
Johannes

Re: Evaluation of variable as f-string

<tr5dk9$2mlid$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21459&group=comp.lang.python#21459

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dfnsonfs...@gmx.de (Johannes Bauer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 10:18:00 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <tr5dk9$2mlid$2@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<8ca25af2-8a5b-b915-4706-da1398d56d24@tompassin.net>
<mailman.1703.1674968790.20444.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 29 Jan 2023 09:18:01 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="1b04e274401c7c621fe2d51272691b37";
logging-data="2840141"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d8tbepEMN96BbN3EULD5BrUJunBBoRKs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:IfX+g7YCNK8keP5zgQCsY3o2/rc=
Content-Language: en-US
In-Reply-To: <mailman.1703.1674968790.20444.python-list@python.org>
 by: Johannes Bauer - Sun, 29 Jan 2023 09:18 UTC

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. That's a good enough answer for
me, actually. I was just thinking that possibly there's something like
(made-up code):

x = { "foo": "bar" }
fstr = string.fstring_compile(s)
fstr.eval(x = x)

Which I didn't know about. It would make sense to me, but possibly not
enough of a usecase to make it into Python. The format() flavors do not

> 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
allows for exactly what f-strings do: execute arbitrary Python snippets
of code and format them in one go. In other words, I want to be able to
do things like that, given an *arbitrary* dictionary x and a string s
(which has the only restriction that its content needs to be vald
f-string grammar):

x = {
"d": 12,
"t": 12345,
"dt": datetime.datetime,
"td": datetime.timedelta
} s = "{x['d']:09b} {'->' * (x['d'] // 3)} {(x['dt'](2000, 1, x['d']) +
x['td'](120)).strftime('%y.%m.%d')} {'<-' * (x['d'] // 4)}"
q = magic_function(s, x = x)

and have "q" then be

'000001100 ->->->-> 00.05.11 <-<-<-'

I believe the closest solution would be using a templating mechanism
(like Mako), but that has slightly different syntax and doesn't do
string formatting as nice as f-strings do. f-strings really are the
perfect syntax for what I want to do.

Cheers,
Johannes

Re: Evaluation of variable as f-string

<tr5k67$2nrah$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21460&group=comp.lang.python#21460

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 12:09:59 +0100
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <tr5k67$2nrah$2@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<mailman.1669.1674849042.20444.python-list@python.org>
<tr1d0t$1r96f$4@dont-email.me> <tr1i5c$1saqj$1@dont-email.me>
<af913477-e2d9-df6e-7a56-27a525f9fc73@tompassin.net>
<mailman.1684.1674871016.20444.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 29 Jan 2023 11:09:59 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="35af1fe2a312bc5db02be37f72badb69";
logging-data="2878801"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+o0PH99diwyp1Gi4GZuSD0MfQfICgcFKE="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Cancel-Lock: sha1:4+7oJX5utSXmmOhzVN298d35lk4=
In-Reply-To: <mailman.1684.1674871016.20444.python-list@python.org>
 by: Christian Gollwitzer - Sun, 29 Jan 2023 11:09 UTC

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:
>>>
>>> x = { "y": "z" }
>>> s = "-> {x['y']}"
>>> print(s.format(x = x))
>>> Traceback (most recent call last):
>>>    File "<stdin>", line 1, in <module>
>>> KeyError: "'y'"
>>>
>>> This. Does. Not. Work.
>>
>> It's because "you're holding it wrong!". Notice the error message; it
>> says that the key 'y' does not exist.
>>
>>
>> (base) Apfelkiste:Abschlussmeeting chris$ ipython
>> Python 3.8.8 (default, Apr 13 2021, 12:59:45)
>> Type 'copyright', 'credits' or 'license' for more information
>> IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
>>
>> In [1]: x = { "y": "z" }
>>
>> In [2]: s = "-> {x[y]}"
>>
>> In [3]: print(s.format(x = x))
>> -> z
>>
>> In [4]:
>>
>>      Christian
>
> Oops, that's not quite what he wrote.
>
> You: s = "-> {x[y]}"    # Works
> Him: s = "-> {x['y']}"  # Fails
>
You might want to reconsider why I could have possibly written this
message....

Christian

To gateway or not to gateway a specific person (was: Evaluation of variable as f-string)

<mailman.1710.1675001716.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21468&group=comp.lang.python#21468

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: To gateway or not to gateway a specific person (was: Evaluation of
variable as f-string)
Date: Sun, 29 Jan 2023 15:15:13 +0100
Lines: 63
Message-ID: <mailman.1710.1675001716.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<f-20230129031404@ram.dialup.fu-berlin.de>
<CAPTjJmo8qoq3ZbHoEKkFnrZiQHZb7vZRPRjHH7G-C2T4EaRNYA@mail.gmail.com>
<20230129141513.sxmsi363jebxyg2x@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="tak7saanposfneoa"
X-Trace: news.uni-berlin.de vfOGvMs6DcUgYweA4olspAqXSIkEjIV9d0nNkD94Vc8A==
Return-Path: <hjp-python@hjp.at>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'content-
type:multipart/signed': 0.05; 'issue.': 0.05; '2023': 0.07; 'ram':
0.07; 'sun,': 0.07; 'angelico': 0.09; 'content-type:application
/pgp-signature': 0.09; 'filename:fname piece:asc': 0.09;
'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'subject:not': 0.09;
'"creative': 0.16; '+1100,': 0.16; '__/': 0.16; 'banned': 0.16;
'challenge!"': 0.16; 'from:addr:hjp-python': 0.16;
'from:addr:hjp.at': 0.16; 'from:name:peter j. holzer': 0.16;
'gatewayed': 0.16; 'hjp@hjp.at': 0.16; 'holzer': 0.16;
'liability.': 0.16; 'moderators': 0.16; 'reality.': 0.16;
'stross,': 0.16; 'subject:string': 0.16; 'subject:variable': 0.16;
'them?': 0.16; 'url-ip:212.17.106.137/32': 0.16; 'url-
ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16; 'url:hjp':
0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'reduce': 0.19; 'to:addr
:python-list': 0.20; 'written': 0.22; "what's": 0.22; 'stefan':
0.26; 'chris': 0.28; 'expect': 0.28; 'sense': 0.28; 'error': 0.29;
'think': 0.32; '(this': 0.32; 'but': 0.32; "i'm": 0.33; 'mailing':
0.33; 'someone': 0.34; 'header:In-Reply-To:1': 0.34; 'posts':
0.36; 'lists': 0.37; 'read': 0.38; 'list': 0.39; 'wishes': 0.40;
'something': 0.40; 'want': 0.40; 'seen': 0.62; 'received:212':
0.62; 'public': 0.63; 'full': 0.64; 'owners': 0.64; 'your': 0.64;
'his': 0.65; 'years': 0.65; 'received:userid': 0.66; 'bad': 0.67;
'technical': 0.67; 'away': 0.67; 'decision': 0.68; 'order': 0.69;
'url-ip:212/8': 0.69; 'copyright': 0.84; 'received:at': 0.84;
'stolen': 0.84; 'subject: \n ': 0.84; 'subject:person': 0.84;
'subject:specific': 0.84; 'caused': 0.86; 'hidden': 0.95
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAPTjJmo8qoq3ZbHoEKkFnrZiQHZb7vZRPRjHH7G-C2T4EaRNYA@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20230129141513.sxmsi363jebxyg2x@hjp.at>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<f-20230129031404@ram.dialup.fu-berlin.de>
<CAPTjJmo8qoq3ZbHoEKkFnrZiQHZb7vZRPRjHH7G-C2T4EaRNYA@mail.gmail.com>
 by: Peter J. Holzer - Sun, 29 Jan 2023 14:15 UTC
Attachments: signature.asc (application/pgp-signature)

On 2023-01-29 15:47:47 +1100, Chris Angelico wrote:
> On Sun, 29 Jan 2023 at 14:36, Stefan Ram <ram@zedat.fu-berlin.de> 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, but if
> you're going to threaten python-list's owners with legal action for
> daring to rebroadcast a public post, I would have to recommend that
> you get promptly banned from the list in order to reduce liability.

Stefan had been banned for years because of this issue. In mid-2021
(wow, that long ago? I thought that was a lot more recently) his posts
started to appear again.

I don't know if this was a concious decision of the moderators, a
technical error or whether Stefan changed something which caused him to
escape the filter.

I don't think it matters. If someone posts to a Usenet group with the
full knowledge that it is gatewayed to a mailing list it is unreasonable
to expect the moderators of the list to jump through hoops to comply
with wishes hidden away in a non-standard header.

> What's so bad about mailing lists that you don't want your messages to
> be seen on them?

He's Stefan Ram :-).

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Evaluation of variable as f-string

<mailman.1713.1675018336.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21474&group=comp.lang.python#21474

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sun, 29 Jan 2023 13:52:02 -0500
Lines: 48
Message-ID: <mailman.1713.1675018336.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<mailman.1669.1674849042.20444.python-list@python.org>
<tr1d0t$1r96f$4@dont-email.me> <tr1i5c$1saqj$1@dont-email.me>
<af913477-e2d9-df6e-7a56-27a525f9fc73@tompassin.net>
<mailman.1684.1674871016.20444.python-list@python.org>
<tr5k67$2nrah$2@dont-email.me>
<dfe4bcf9-5f33-3b56-416e-127328c3f7bf@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de wC9OTZw2qrdEfmKwMGN03w50splUd6vIZgJ8YyOz6Huw==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=TQQoiswm;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; 'last):': 0.05; 'python.': 0.08; 'fails': 0.09;
'received:23.83.212': 0.09; 'received:elm.relay.mailchannels.net':
0.09; 'schrieb': 0.09; '>>>>': 0.16; '[1]:': 0.16; '[2]:': 0.16;
'gollwitzer': 0.16; 'ipython': 0.16; 'received:10.0.0': 0.16;
'received:64.90': 0.16; 'received:64.90.62': 0.16;
'received:64.90.62.162': 0.16; 'received:dreamhost.com': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'wrote:': 0.16;
'python': 0.16; 'says': 0.17; 'pm,': 0.19; 'to:addr:python-list':
0.20; 'written': 0.22; 'help.': 0.25; '>>>': 0.28; 'error': 0.29;
'header:User-Agent:1': 0.30; 'am,': 0.31; '"",': 0.32;
'christian': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'work.': 0.34; 'header
:In-Reply-To:1': 0.34; 'possibly': 0.36; "it's": 0.37; 'this.':
0.37; 'file': 0.38; 'could': 0.38; 'quite': 0.39; 'want': 0.40;
'gave': 0.61; 'skip:\xc2 10': 0.62; 'key': 0.64; 'wish': 0.66;
'header:Received:6': 0.67; 'received:64': 0.67; 'claim': 0.71;
'ignore': 0.71; '"you\'re': 0.84; 'literally': 0.84; 'message;':
0.84; 'you:': 0.84; 'convey': 0.91
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1675018324; a=rsa-sha256;
cv=none;
b=WfVkbR4YESrRdSvvjpQb/Ns2mjR5V9+DupT+fUUkeGfYVvvKgc+XQ2txoRE2WaAojmavwO
jG1EzRn88RcpEqH8tcLvMkpKbS0jO1KiNkfeExYgfR+fZ50Op5zGNJAeLwhllsjMMaOD1w
FA/PHHiimhXfbGk2lQTeapEqwUoSSOwLRrvGKquHTsnERTIzVWwzaJ3cqp36wK2iHVOyJE
UU+T24CKEsVDpZqEf/DjUFO7QMhRywlJA2ATZeSNAwnu7xD12FRZGNIFwBtAsE762zYO27
t7un0LC9K0B6H8Udk+asyrQgZQ0V8naIwtdEiRSi7M1cLtvjUE7AL8gvqkBhCA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1675018324;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=Ocst6zoeG/kgVAXs0ibHpMAr1fhVsEOrYSFjIvFNZr0=;
b=biR09ChqCz0zTkH/t6IHqE20iPgu5CboUzni2OWMuizOXd2G5lIxfpHBn4sDpg0MMahJ1F
FPwdTr1a/l62ZnWWCQvB6tpyoiIjPEXxtq949S1wt1Nu3bXK52b6ucFYvzMKEPWGFvWqvf
GSGMqEuEHMfB9GZ21uRr4qmoEL/8qKIhtAWkPvRXLQDa4FDgXlYORsOdSL3Ru9nE24lpuz
1uOscvV14RGc7K73QwUPZkctwXcPBISzVktMXjAVJDxJUt2iYnVOZ9uZM3GsbndqCHraZG
Ws1rOkj5gp+x7vx6E3oMOQG+XH0Rt0nOOqXlzBTzXtcGcMXeN64fHBJEL5bvQA==
ARC-Authentication-Results: i=1; rspamd-544f66f495-wqxhf;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Abortive-Abortive: 373021477c992b21_1675018324240_1390172883
X-MC-Loop-Signature: 1675018324240:2887601910
X-MC-Ingress-Time: 1675018324240
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1675018323;
bh=Ocst6zoeG/kgVAXs0ibHpMAr1fhVsEOrYSFjIvFNZr0=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=TQQoiswmlvd88RLJr9wvIDebqHaBKjk8uB0YcWYw74NuLT6Qgf8weG0XZzAsmYf+y
w1h1SnIC3ZUxg1BN8EytKIeKLwMpOKsFSZzNCczu/n+MCkFgKNuPQPINy4BKelBV5K
lNtFukUWQxni7l9J+DDnRGE7M+iTicWdwGuBFoXDsoNLG2K0d8mYky6FcuX7c9kzZo
MGghYQd/V2z7GeYtXzRKaoG2coStewEkjp+0aOpFKaN2hY8snXxJkGVGUHr3Floh04
aTPFmAmwB+56G33D+NBpmuBgAd7AlmL02890op6RWDgiDUnYHKiK16SjFH+wG6Z/Y/
o85snA3G1gnAA==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <tr5k67$2nrah$2@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <dfe4bcf9-5f33-3b56-416e-127328c3f7bf@tompassin.net>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<mailman.1669.1674849042.20444.python-list@python.org>
<tr1d0t$1r96f$4@dont-email.me> <tr1i5c$1saqj$1@dont-email.me>
<af913477-e2d9-df6e-7a56-27a525f9fc73@tompassin.net>
<mailman.1684.1674871016.20444.python-list@python.org>
<tr5k67$2nrah$2@dont-email.me>
 by: Thomas Passin - Sun, 29 Jan 2023 18:52 UTC

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 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):
>>>>    File "<stdin>", line 1, in <module>
>>>> KeyError: "'y'"
>>>>
>>>> This. Does. Not. Work.
>>>
>>> It's because "you're holding it wrong!". Notice the error message; it
>>> says that the key 'y' does not exist.
>>>
>>>
>>> (base) Apfelkiste:Abschlussmeeting chris$ ipython
>>> Python 3.8.8 (default, Apr 13 2021, 12:59:45)
>>> Type 'copyright', 'credits' or 'license' for more information
>>> IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
>>>
>>> In [1]: x = { "y": "z" }
>>>
>>> In [2]: s = "-> {x[y]}"
>>>
>>> In [3]: print(s.format(x = x))
>>> -> z
>>>
>>> In [4]:
>>>
>>>      Christian
>>
>> Oops, that's not quite what he wrote.
>>
>> You: s = "-> {x[y]}"    # Works
>> Him: s = "-> {x['y']}"  # Fails
>>
> You might want to reconsider why I could have possibly written this
> message....

I might .. or I might wish you had actually said what you wanted to
convey ...

Re: Evaluation of variable as f-string

<mailman.1714.1675037454.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21476&group=comp.lang.python#21476

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hjp-pyt...@hjp.at (Peter J. Holzer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Mon, 30 Jan 2023 01:10:50 +0100
Lines: 57
Message-ID: <mailman.1714.1675037454.20444.python-list@python.org>
References: <d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<8ca25af2-8a5b-b915-4706-da1398d56d24@tompassin.net>
<mailman.1703.1674968790.20444.python-list@python.org>
<tr5dk9$2mlid$2@dont-email.me>
<20230130001050.qpb22dxa72c22pvj@hjp.at>
Mime-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
protocol="application/pgp-signature"; boundary="ygbqhogdjtoya4pg"
X-Trace: news.uni-berlin.de 1UE0a/bh0dBDS3nZ0F4QRQRC7nOqQFx+FPfGBcWqpWiA==
Return-Path: <hjp-python@hjp.at>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'content-
type:multipart/signed': 0.05; 'is.': 0.05; 'string': 0.07;
'content-type:application/pgp-signature': 0.09; 'filename:fname
piece:asc': 0.09; 'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'mechanism': 0.09;
'schrieb': 0.09; 'snippets': 0.09; '"creative': 0.16; '__/': 0.16;
'arbitrary': 0.16; 'challenge!"': 0.16; 'construct.': 0.16;
'from:addr:hjp-python': 0.16; 'from:addr:hjp.at': 0.16;
'from:name:peter j. holzer': 0.16; 'hjp@hjp.at': 0.16; 'holzer':
0.16; 'reality.': 0.16; 'stross,': 0.16; 'subject:string': 0.16;
'subject:variable': 0.16; 'url-ip:212.17.106.137/32': 0.16; 'url-
ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16; 'url:hjp':
0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr
:python-list': 0.20; 'code': 0.23; "isn't": 0.27; 'sense': 0.28;
'accomplish': 0.32; 'do.': 0.32; 'words,': 0.32; 'there': 0.33;
'able': 0.34; 'header:In-Reply-To:1': 0.34; "it's": 0.37; 'way':
0.38; 'use': 0.39; 'wrote': 0.39; 'want': 0.40; 'format': 0.62;
'received:212': 0.62; 'received:userid': 0.66; 'that,': 0.67;
'exactly': 0.68; 'know.': 0.68; 'url-ip:212/8': 0.69; 'practical':
0.84; 'received:at': 0.84; 'want.': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <tr5dk9$2mlid$2@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20230130001050.qpb22dxa72c22pvj@hjp.at>
X-Mailman-Original-References: <d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be>
<5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net>
<mailman.1613.1674675531.20444.python-list@python.org>
<tr1ces$1r96f$3@dont-email.me>
<9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net>
<mailman.1683.1674870701.20444.python-list@python.org>
<tr3uas$2buff$1@dont-email.me>
<8ca25af2-8a5b-b915-4706-da1398d56d24@tompassin.net>
<mailman.1703.1674968790.20444.python-list@python.org>
<tr5dk9$2mlid$2@dont-email.me>
 by: Peter J. Holzer - Mon, 30 Jan 2023 00:10 UTC
Attachments: signature.asc (application/pgp-signature)

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
> allows for exactly what f-strings do: execute arbitrary Python snippets of
> code

That exists. Use eval (or exec).

> and format them in one go.

Include an f-string in the code you eval.

> In other words, I want to be able to do things like that, given an
> *arbitrary* dictionary x and a string s

As I wrote before: An f-string isn't a string. It's a grammatical
construct. So you want to execute Python code which is what eval and
exec do.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

Attachments: signature.asc (application/pgp-signature)
Re: Evaluation of variable as f-string

<f-string-20230131191610@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21493&group=comp.lang.python#21493

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: 31 Jan 2023 18:17:23 GMT
Organization: Stefan Ram
Lines: 25
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <f-string-20230131191610@ram.dialup.fu-berlin.de>
References: <tqmcbf$vdl$1@gioia.aioe.org> <d4a54200-1847-4fd2-c7e1-aa1189f63b78@vub.be> <5bb2546d-8c16-262d-9336-5b41cbf992b5@tompassin.net> <mailman.1613.1674675531.20444.python-list@python.org> <tr1ces$1r96f$3@dont-email.me> <9db7a5e1-076c-a9aa-aee4-e044e45decb7@tompassin.net> <mailman.1683.1674870701.20444.python-list@python.org> <tr3uas$2buff$1@dont-email.me> <f-20230129031404@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 0Jui79HPkvKeorfemQttYgk0a46ZyM2iAeblgphHJuZp7p
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 31 Jan 2023 18:17 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>Then what about,
>name = input( 'name of the dictionary? ' )
>s = input( 'string? ' )
>dictionary = eval( input( 'dictionary? ' ))
>print( eval( s, {name:dictionary} ))

This works always if the client or user adds the "f" for the
f-string at the start of his string himself. The next program shows
an approach that will not work always, but often.

def evaluate_as_fstring( s ):
if '"""' in s and "'''" in s:
raise Exception( "String contains both \"\"\" and '''!" )
elif '"""' in s: return eval( "f'''" + s + "'''" )
else: return eval( 'f"""' + s + '"""' )

x ={ "y": "z" }

print( evaluate_as_fstring( "-> {x['y']}" ))
print( evaluate_as_fstring( '-> {x["y"]}' ))
print( evaluate_as_fstring( "-> {x['''y''']}" ))
print( evaluate_as_fstring( '-> {x["""y"""]}' ))

Re: Evaluation of variable as f-string

<mailman.1729.1675203165.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21499&group=comp.lang.python#21499

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cli...@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Sat, 28 Jan 2023 16:39:49 +0000
Lines: 121
Message-ID: <mailman.1729.1675203165.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de NGs/BAsMHASqclagXZEtGQ9WpcEG5mK1p0M+yQMPrdpw==
Return-Path: <rob.cliffe@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=QFiqjUAs;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.011
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; '(to': 0.07;
'2023': 0.07; 'partial': 0.07; 'pep': 0.07; 'string': 0.07;
'python.': 0.08; '"just': 0.09; 'angelico': 0.09; 'confess': 0.09;
'mechanism': 0.09; 'sometimes,': 0.09; 'string,': 0.09;
'problem.': 0.15; '(except': 0.16; '(so': 0.16; '701': 0.16;
'>>>>': 0.16; 'arbitrary': 0.16; 'are.\xc2\xa0': 0.16; 'cases,':
0.16; 'characters.': 0.16; 'dictionary,': 0.16; 'expressions':
0.16; 'idea.': 0.16; 'indeed': 0.16; 'introduces': 0.16;
'limitations.': 0.16; 'print(x)': 0.16; 'results,': 0.16;
'runtime': 0.16; 'solved': 0.16; 'string:': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'typing': 0.16;
'wrote:': 0.16; "can't": 0.17; 'solve': 0.19; 'to:addr:python-
list': 0.20; 'language': 0.21; 'i.e.': 0.22; 'maybe': 0.22;
'sat,': 0.22; 'code': 0.23; 'idea': 0.24; '(and': 0.25;
'anything': 0.25; 'saying': 0.25; 'stuff': 0.25; 'anyone': 0.25;
'suspect': 0.26; "isn't": 0.27; 'bit': 0.27; 'function': 0.27;
'done': 0.28; 'chris': 0.28; 'expect': 0.28; 'thinking': 0.28;
'email addr:python.org&gt;': 0.28; 'wrong': 0.28; 'header:User-
Agent:1': 0.30; 'wondering': 0.31; 'program': 0.31; 'think': 0.32;
"doesn't": 0.32; 'question': 0.32; 'do.': 0.32; 'here,': 0.32;
'language.': 0.32; 'python-list': 0.32; 'received:192.168.1':
0.32; 'but': 0.32; 'there': 0.33; 'same': 0.34; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'definitely': 0.35; 'addressed':
0.36; 'work,': 0.36; 'people': 0.36; 'source': 0.36; "skip:' 10":
0.37; 'currently': 0.37; "it's": 0.37; 'class': 0.37; 'this.':
0.37; 'received:192.168': 0.37; 'though': 0.37; 'could': 0.38;
'means': 0.38; 'thanks': 0.38; 'use': 0.39; 'decide': 0.39;
'neither': 0.39; 'seeing': 0.39; 'to.': 0.39; 'still': 0.40;
'exact': 0.40; 'overflow:': 0.40; 'received:213': 0.40; 'wishes':
0.40; 'something': 0.40; 'want': 0.40; 'should': 0.40; 'best':
0.61; 'remember': 0.61; 'skip:h 10': 0.61; "there's": 0.61;
'seen': 0.62; 'here': 0.62; 'great': 0.63; 'pass': 0.64; "you'd":
0.64; 'research': 0.64; 'full': 0.64; 'your': 0.64; 'well': 0.65;
'required': 0.65; 'skip:t 20': 0.66; 'skip:e 20': 0.67; 'that,':
0.67; 'right': 0.68; 'exactly': 0.68; 'matter': 0.68; 'order':
0.69; 'and,': 0.69; 'important.': 0.69; 'obvious': 0.69; 'skip:f
30': 0.71; 'head': 0.73; 'quote': 0.74; '....': 0.76;
'implemented': 0.76; 'yes': 0.76; 'points': 0.84; '*for': 0.84;
'email name:&lt;python-list': 0.84; 'extent': 0.84; 'luck': 0.84;
'made,': 0.84; 'realise': 0.84; 'rob': 0.84; 'entitled': 0.91;
'me:': 0.91; 'two.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1674924004;
bh=ayIlwF7nJQpp0+Lp6CDv719Jc67v1gmxyu6FeWz6qD0=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=QFiqjUAsr6PG1WihnkuzW8MY3MCjyxHXt+MznPqJn4QDP4CXwJH67XiasfjiP0jVD0gu4DGn9VZbmJcIwcGUbhfQHxclD/82G24gbbdf+ROUd+tRBvEhYR/01Ia7XJQayNXPsVZm240cqi1//CYXjVHZFtfooRIhYGGApHw2J9eK1IR9JtoPRKp4k+ctMMIQkJqCaT9IDh5pwl0OuDJGCMynJo74gjyA9RRDi7PB1roBFfivApjdd74oFeUXO6EwQn3Go9g4AQ03oVa9GCMS/jI0fd9t+vg9KqeQBy7DW2uI2NyqVz1/xLACQaNHXwpWC1bZPw+Bw1lPmBq/dnER1w==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613942904D891B4D
X-Originating-IP: [109.149.69.127]
X-OWM-Source-IP: 109.149.69.127 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvhedruddvkedgledtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtfeejnecuhfhrohhmpeftohgsucevlhhifhhfvgcuoehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpedutefgueduveevleelhffhgeeuhfefveduudfhvdffheevhefhvedvjeeijeettdenucfkphepuddtledrudegledrieelrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurddvtdegngdpihhnvghtpedutdelrddugeelrdeiledruddvjedpmhgrihhlfhhrohhmpehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhg
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-GB
In-Reply-To: <CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
 by: Rob Cliffe - Sat, 28 Jan 2023 16:39 UTC

On 27/01/2023 23:41, Chris Angelico wrote:
> On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list
> <python-list@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.
>
>> If it's addressed to me: How about if I wanted a program (a learning
>> tool) to allow the user to play with f-strings?
>> I.e. to type in a string, and then see what the result would be if it
>> had been an f-string?
>> I suspect there are other use cases, but I confess I can't think of one
>> right now.
> Use the REPL, which will happily evaluate f-strings in their original
> context, just like any other code would. You're already eval'ing, so
> it's exactly what you'd expect. This is not the same thing as "typing
> in a string", though - it's typing in code and seeing what the result
> would be. (Except to the extent that source code can be considered a
> string.)
This is hypothetical, but I might want to work on a platform where the
REPL was not available.
>
>> If it's addressed to me: "it" means a function that will take a string
>> and evaluate it at runtime as if it were an f-string. Sure, with
>> caveats and limitations.
> And that's what I am saying is a terrible terrible idea. It will
> evaluate things in the wrong context, it has all the normal problems
> of eval, and then it introduces its own unique problems with quote
> characters.
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 *he* needs, and that the drawbacks don't matter *for
him".  Just as you're entitled to disagree.
>
>> And indeed Thomas Passim found this partial
>> solution on Stack Overflow:
>> def effify(non_f_str: str):
>> return eval(f'f"""{non_f_str}"""')
> You can find anything on Stack Overflow. Just because you found it
> there doesn't mean it's any good - even if it's been massively
> upvoted.
>
>> Addressing your points specifically:
>> 1) I believe the quote character limitation could be overcome. It
>> would need a fair amount of work, for which I haven't (yet) the time or
>> inclination.
> No problem. Here, solve it for this string:
>
> eval_me = ' f"""{f\'\'\'{f"{f\'{1+2}\'}"}\'\'\'}""" '
>
> F-strings can be nested, remember.
I remember it well.
As far as I can see (and I may well be wrong; thinking about this
example made my head hurt 😁) this could be solved if PEP 701 were
implemented (so that f-string expressions can contain backslashes) but
not otherwise.
>
>> 2) Yes in general you would have to pass it one dictionary, maybe
>> two. I don't see this as an insuperable obstacle. I am not sure what
>> you mean by "can't be done with full generality" and perhaps that's not
>> important.
>>>> def func():
> ... x = 1
> ... class cls:
> ... y = 2
> ... print(f"{x=} {y=}")
> ... print(locals())
> ...
>>>> func()
> x=1 y=2
> {'__module__': '__main__', '__qualname__': 'func.<locals>.cls', 'y': 2}
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 nonlocals()
dictionary?
>
> Maybe you don't care. Maybe you do. But locals() is not the same as
> "all names currently available in this scope". And, this example is
> definitely not something I would recommend, but good luck making this
> work with eval:
>
>>>> def func():
> ... x = 1
> ... print(f"{(x:=2)}")
> ... print(x)
> ...
>>>> func()
> 2
> 2
> ... x = 1
> ... print(eval("(x:=2)", globals(), locals()))
> ... print(x)
> ...
>>>> func()
> 2
> 1
Now that, I have to admit, IS a challenge!
>
>> 3) Not sure I understand this.
> Before f-strings existed, one of the big problems with "just use
> str.format_map" was that you can't just pass it locals() to get all
> the available names. You also can't eval arbitrary code and expect to
> get the same results, even if you pass it globals and locals. And
> various other considerations here - the exact issues seen here, but
> flipped on their heads. So the obvious question is: why not just use
> str.format_map?
>
What this underlines to me is what a good thing f-strings are.  And with
PEP 701 they will be IMO even better.
Just as when you were working on PEP 463 (Exception-catching
expressions) - which I still think would be a Good Thing - some research
I did made me realise how good the existing try/except/else/finally
mechanism actually is.  There's lots of Good Stuff in Python. 😁
Best wishes
Rob

Re: Evaluation of variable as f-string

<mailman.1730.1675204439.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21500&group=comp.lang.python#21500

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Wed, 1 Feb 2023 09:33:45 +1100
Lines: 76
Message-ID: <mailman.1730.1675204439.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de fzm0fp8U7vNxm51fwZOMIgVHEE3t5XLoV6sfgw1ZBrMA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=cbuRyf7c;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.018
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'def': 0.04; 'containing':
0.05; '(to': 0.07; '2023': 0.07; 'happened': 0.07; 'compiler':
0.09; 'depend': 0.09; 'readable': 0.09; '"don\'t': 0.16; '>>>>':
0.16; 'cases,': 0.16; 'chrisa': 0.16; 'construct.': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'idea.': 0.16; 'print(x)': 0.16; 'self.name': 0.16;
'subject:string': 0.16; 'subject:variable': 0.16; 'such,': 0.16;
'variable,': 0.16; 'wrote:': 0.16; 'python': 0.16; 'feb': 0.17;
'probably': 0.17; 'to:addr:python-list': 0.20; 'written': 0.22;
'maybe': 0.22; 'skip:_ 10': 0.22; 'idea': 0.24; 'anything': 0.25;
'anyone': 0.25; "isn't": 0.27; 'function': 0.27; '>>>': 0.28;
'it,': 0.29; 'wondering': 0.31; 'think': 0.32; "doesn't": 0.32;
'do.': 0.32; 'python-list': 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'same': 0.34;
'mean': 0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'definitely': 0.35; 'yes,': 0.35; 'from:addr:gmail.com':
0.35; 'functions': 0.36; 'change': 0.36; 'currently': 0.37;
"it's": 0.37; 'received:209.85': 0.37; 'class': 0.37; 'way': 0.38;
'could': 0.38; 'thanks': 0.38; 'received:209': 0.39;
'received:209.85.208': 0.39; 'decide': 0.39; 'neither': 0.39;
'wed,': 0.39; 'still': 0.40; 'deleting': 0.40; 'limited.': 0.40;
'wants': 0.40; 'both': 0.40; 'something': 0.40; 'should': 0.40;
'ever': 0.63; 'great': 0.63; 'copy': 0.63; 'thus': 0.64; 'bad':
0.67; 'that,': 0.67; 'right': 0.68; 'matter': 0.68; 'and,': 0.69;
'free': 0.72; '....': 0.76; 'star': 0.76; 'highly': 0.78;
'apologize': 0.81; '*for': 0.84; 'exactly.': 0.84; 'imports':
0.84; 'luck': 0.84; 'lying': 0.84; 'rob': 0.84; 'entitled': 0.91;
'retained': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=5B6D5gwvvcQ7n6FPNseOS0JzXWm0yNs0AFvS2Z1B5s0=;
b=cbuRyf7c+9J6f2TWnV5V42c82VfMqRzl4H+qPKCBWJ978yTy67R5dG7Ii+WF+oA+Dh
HCCZkSLt8JFyCfqvU+EFxmwBiSSIFMB5bujOP8DktX5XCbiPYvATCTytF89ihhh3MGY/
7dU0J/vt0O3QS5i4Ew28G3S46fNglmH7mrouv69cEq4oJQqcDEGHHCZhS09obBuZZ/Tl
O6OPzKGNDdDbITCzE5loYy+4Ik8abObEl8ZI80IxwOuqAvOue5nZlEY3GrYaQ9XKTR5G
iwTKexWMxiKANcnLqeFzRlJVcRch8a2kIy3Nv7nvAukir4/SExv/W6lqexay5ESzQIPl
WtGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=5B6D5gwvvcQ7n6FPNseOS0JzXWm0yNs0AFvS2Z1B5s0=;
b=HeOrQ4Fh1dP7+T2IwkP1FNGY5Rsm+VJQmzxBQ4Kkgu4n7YD8LxsvmPr/eB2MmjxzRh
ZzoIuSptRL8tlzZLN2rbF+7sGHP4KDsUTlkSBr6ALzF32/xcwFdoQeDoJkLgRu1AOyZ9
1hV22gtAzKEMu44UXvSzR+qAjIzIq8dT41tch4vSLUUjOsK08Glrodllx731Xuuf3C5O
hk4GWc+AQkyuZWqBVQqUDch8Vz0ca+TazYbDMay1bTUZIaMUVMFafumd84KC8GaHpYD1
pnCyPhFFyc8uhqBNoRJK0YftL8PZgNWCodwxzAQomymTSH7jVwf06JMEsCMl6SMMVHbj
sgAQ==
X-Gm-Message-State: AO0yUKU81GxkUbKMIrONJ0/MNWbaOJpDExKpVKgAD/7cld1Bxd+kEFvw
VO9Aab6PzLe7GvSbs+xnIbbbnCpl0gd1Kr/d8d+FJOi9ASQ=
X-Google-Smtp-Source: AK7set+AUhQbet4UZrXrnOH1dzeqaaNCjpg/XLZ2V3Z1sAcP/A6kC3OYMlehAkMSKRtGvlh/+0CtO7hlPVfKA5VbbVc=
X-Received: by 2002:a05:6402:449a:b0:49c:a68c:8b6b with SMTP id
er26-20020a056402449a00b0049ca68c8b6bmr286007edb.84.1675204437397; Tue, 31
Jan 2023 14:33:57 -0800 (PST)
In-Reply-To: <33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
 by: Chris Angelico - Tue, 31 Jan 2023 22:33 UTC

On Wed, 1 Feb 2023 at 09:14, Rob Cliffe via Python-list
<python-list@python.org> 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 *he* needs, and that the drawbacks don't matter *for
> him". Just as you're entitled to disagree.

It's an objectively bad idea. If the OP wants to do it, well, it's a
free world, but that doesn't mean I'm going to sugarcoat it and say
"oh yes, yes, you are totally right to do that".

> 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 nonlocals()
> dictionary?

I don't think so, but there might be some value in a dictionary
containing all available variables. It would have the same "don't
depend on writing" caveats that locals() has (or would be specifically
defined as a copy and thus disconnected), so its value would be
limited. And it would probably STILL be imperfect, because perfection
would require that it be a compiler construct, due to the way that
nonlocals are implemented.

>>> class Destructible:
.... def __init__(self, name): self.name = name
.... def __del__(self): print("Deleting", self.name)
....
>>> def func():
.... x = Destructible("x")
.... y = Destructible("y")
.... return lambda: x
....
>>> func()
Deleting y
<function func.<locals>.<lambda> at 0x7ff8c9897ce0>

The compiler is free to dispose of y as soon as func ends, but x has
to be retained for the inner function. So if there were any function
that could return every readable variable, it would have to force both
x and y to be retained; as such, it would have to be a compiler
construct. And given what happened with star imports in functions as
of Python 3, I am highly dubious that such a pessimisation would ever
be implemented.

> > Maybe you don't care. Maybe you do. But locals() is not the same as
> > "all names currently available in this scope". And, this example is
> > definitely not something I would recommend, but good luck making this
> > work with eval:
> >
> >>>> def func():
> > ... x = 1
> > ... print(f"{(x:=2)}")
> > ... print(x)
> > ...
> >>>> func()
> > 2
> > 2
> > ... x = 1
> > ... print(eval("(x:=2)", globals(), locals()))
> > ... print(x)
> > ...
> >>>> func()
> > 2
> > 1
> Now that, I have to admit, IS a challenge!

Exactly. This sort of thing is why the OP's idea as written is so bad:
it will cause many unnecessary corner cases, where the much simpler
idea of working it around format_map will actually behave sanely.

So I do not apologize for calling it a bad idea. It is a bad idea.
Lying about it won't change anything and won't help anyone.

ChrisA

Re: Evaluation of variable as f-string

<trrk03$35tfv$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21602&group=comp.lang.python#21602

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dfnsonfs...@gmx.de (Johannes Bauer)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Mon, 6 Feb 2023 20:21:39 +0100
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <trrk03$35tfv$1@dont-email.me>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<mailman.1730.1675204439.20444.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Feb 2023 19:21:39 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="5a2ecda0859222be94a9974a596c9f97";
logging-data="3339775"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2pRrHnOB3/5x4jDLQ6GxklZIRkBHYPB8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:A3eugFhcCH+m1mv57z2ZM/8C9WM=
Content-Language: en-US
In-Reply-To: <mailman.1730.1675204439.20444.python-list@python.org>
 by: Johannes Bauer - Mon, 6 Feb 2023 19:21 UTC

Am 31.01.23 um 23:33 schrieb Chris Angelico:

> It's an objectively bad idea. If the OP wants to do it, well, it's a
> free world, but that doesn't mean I'm going to sugarcoat it and say
> "oh yes, yes, you are totally right to do that".

It is pretty baffling how convinced you are of yourself. It would be
amusing if it weren't so toxic.

> Exactly. This sort of thing is why the OP's idea as written is so bad:
> it will cause many unnecessary corner cases, where the much simpler
> idea of working it around format_map will actually behave sanely.

Except, as I have pointed out over and over and over again: your
"solution" does not fit the criteria.

You're calling a lugnut an "objectively bad idea" because obviously in
their right mind would want to use a nail. You're completely ignoring
what my intended solution provides and claiming that your non-solution
solves the problem.

It. Does. Not.

I find it shocking that you are unable to grasp a concept so simple.

> So I do not apologize for calling it a bad idea. It is a bad idea.
> Lying about it won't change anything and won't help anyone.

You know what's objectively worse than a solution that has drawbacks?
One that doesn't solve the issue in *the slightest*, just as *all* of
your suggestions have.

It's quite ridiculous that you critize a solution with such conviction
but are only able to provide completely dysfunctional "alternatives",
utterly broken and without a hint of the requested functionaly. Yet you
claim your solution is "objectively better". This is totally nuts.

I withdraw my earlier statement that you seem to be technically
competent. You have absolutely and utterly no clue what you are talking
about, yet reiterate and advocate "solutions" that are none. This is
pathetic.

Cheers,
Johannes

Re: Evaluation of variable as f-string

<mailman.1779.1675784381.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21609&group=comp.lang.python#21609

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cli...@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Tue, 7 Feb 2023 15:12:08 +0000
Lines: 23
Message-ID: <mailman.1779.1675784381.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de /XAsPBK8n1tJBW2LUWLKEQaVnbBjn5AZr4GkUJy+L55w==
Return-Path: <rob.cliffe@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=da5a8nAN;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'containing': 0.05; '(to':
0.07; 'angelico': 0.09; 'compiler': 0.09; 'construct': 0.09;
'depend': 0.09; 'possible,': 0.15; '"don\'t': 0.16; '(built-in)':
0.16; 'constructed': 0.16; 'run-time': 0.16; 'subject:string':
0.16; 'subject:variable': 0.16; 'wrote:': 0.16; 'python': 0.16;
'probably': 0.17; 'to:addr:python-list': 0.20; 'function': 0.27;
'chris': 0.28; 'header:User-Agent:1': 0.30; 'wondering': 0.31;
'think': 0.32; 'received:192.168.1': 0.32; 'but': 0.32; 'there':
0.33; 'same': 0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:192.168': 0.37; 'way': 0.38; 'could': 0.38; 'thanks':
0.38; 'list': 0.39; 'neither': 0.39; 'still': 0.40; 'limited.':
0.40; 'received:213': 0.40; 'wishes': 0.40; 'both': 0.40;
'should': 0.40; 'best': 0.61; 'send': 0.63; 'copy': 0.63; 'thus':
0.64; 'speed': 0.71; 'bounced': 0.84; 'demand.': 0.84; 'rob': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1675782746;
bh=BXYpvN0Exh3B+Z2SveXt8OR+6QSA4dHm2I7TSdP0aIQ=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=da5a8nANth0aDF7+sWkd3d+Q5rb64onMaRUvKQDfFZde3Fw5FawRTnB3rYmgeNUZEPFMfsrolvV+/roPoYR/xbRLsGFQSu9PqCPZWNWmPqdW3fd6NCE394j8F1AJgjKB95AJykY3rQGTFO90yYLJ2wA3c0yhhBmuKH+v+UrinnQuZzOEgnL1M02h9iJAud9U1/uJPIItjHIf2SUzQ87L+5q9vy05YNi4m6KdtinGTxcAQQDcJN+8/bOSM7Q5UJnlx4Rc1/WvxDv3luuPN2VtjzhY2iRnIjBaMhn57bPxJLJpXNHAmMjRboSdN2GTASq7nsYWPFdhW2d6mVqFlh0ArA==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 6139417C4EC07A41
X-Originating-IP: [109.149.69.127]
X-OWM-Source-IP: 109.149.69.127 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvhedrudegkedgjeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptfhosgcuvehlihhffhgvuceorhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepvdetudfhtefgveegieffleelvdeugfeikeevveehudetgfevieejfedtteevtdegnecukfhppedutdelrddugeelrdeiledruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegludelvddrudeikedruddrvddtgegnpdhinhgvthepuddtledrudegledrieelrdduvdejpdhmrghilhhfrhhomheprhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomhdpnhgspghrtghpthhtohepvddprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrghdprhgtphhtthhopehrohhsuhgrvhesghhmrghilhdrtghomh
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-GB
In-Reply-To: <CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
X-Mailman-Approved-At: Tue, 07 Feb 2023 10:39:41 -0500
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
 by: Rob Cliffe - Tue, 7 Feb 2023 15:12 UTC

[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 nonlocals()
>> dictionary?
> I don't think so, but there might be some value in a dictionary
> containing all available variables. It would have the same "don't
> depend on writing" caveats that locals() has (or would be specifically
> defined as a copy and thus disconnected), so its value would be
> limited. And it would probably STILL be imperfect, because perfection
> would require that it be a compiler construct, due to the way that
> nonlocals are implemented.
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
would be no impact on Python run-time speed if it were only constructed
on demand.

Best wishes
Rob

Re: Evaluation of variable as f-string

<nonlocal-20230207173920@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21610&group=comp.lang.python#21610

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: 7 Feb 2023 16:41:45 GMT
Organization: Stefan Ram
Lines: 30
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <nonlocal-20230207173920@ram.dialup.fu-berlin.de>
References: <tqmcbf$vdl$1@gioia.aioe.org> <CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com> <ebb89997-603f-6283-742a-121128e55ae8@btinternet.com> <CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com> <8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com> <CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com> <33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com> <CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com> <d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com> <mailman.1779.1675784381.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de mDEYYfHlxeOLzZI0ji4mowbAuhbbYQJliGcPXicPM6Oieu
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 7 Feb 2023 16:41 UTC

Rob Cliffe <rob.cliffe@btinternet.com> 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
>would be no impact on Python run-time speed if it were only constructed
>on demand.

Here's a quick attempt to get local and non-local names as a set.
It might only work under some implementations of Python.

main.py

set_class = set

def f():
x = 0
def g():
set = set_class()
for n in g.__qualname__.split( '.' ):
if n != '<locals>':
set = set.union( set_class( eval( n ).__code__.co_varnames ))
print( set )
g()
f()

output

{'n', 'set', 'x'}

Re: Evaluation of variable as f-string

<mailman.1780.1675794562.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21612&group=comp.lang.python#21612

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Wed, 8 Feb 2023 04:46:52 +1100
Lines: 41
Message-ID: <mailman.1780.1675794562.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
<CAPTjJmo_3tgunRswY7LE4mXuDykiPqFqN0W-d1NUbRv=td1G3w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 4cX+H5YxxZ7/PPwZoLqIrgWvpSlKvhyuYgqC6fQ+bi+A==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=XnQ3GIMd;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'containing':
0.05; '(to': 0.07; '2023': 0.07; 'angelico': 0.09; 'compiler':
0.09; 'construct': 0.09; 'depend': 0.09; 'possible,': 0.15;
'"don\'t': 0.16; '(built-in)': 0.16; 'builtin': 0.16; 'chrisa':
0.16; 'constructed': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'nested': 0.16;
'received:209.85.218': 0.16; 'run-time': 0.16; 'subject:string':
0.16; 'subject:variable': 0.16; 'values?': 0.16; 'wrote:': 0.16;
'python': 0.16; 'feb': 0.17; 'probably': 0.17; "can't": 0.17;
'to:addr:python-list': 0.20; 'code': 0.23; 'function': 0.27;
'chris': 0.28; 'wondering': 0.31; 'think': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'there': 0.33; 'same':
0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'functions': 0.36; 'special': 0.37; "it's": 0.37;
'received:209.85': 0.37; 'way': 0.38; 'could': 0.38; 'thanks':
0.38; 'received:209': 0.39; 'quite': 0.39; 'list': 0.39;
'neither': 0.39; 'wed,': 0.39; 'still': 0.40; 'limited.': 0.40;
'both': 0.40; 'should': 0.40; 'send': 0.63; 'copy': 0.63; 'thus':
0.64; 'your': 0.64; '100%': 0.66; 'it:': 0.69; 'speed': 0.71;
'longer': 0.71; 'bounced': 0.84; 'demand.': 0.84; 'rob': 0.84;
'reliable.': 0.91; 'magic': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=kvNuswlK9hsXfoQuDvUPLhH6tDa0cGcPMehJLdbQqwM=;
b=XnQ3GIMdQz9a5gAdSw+y7tAzsc8F7qB60zc0F4KVFfPjBtceFwntue/2gjKPSjTYXQ
lIKFKjKfQVFVNMmHiTJ7oSEH0JeB2nCLSbU3E7BrxQ8k1ld2Gv0SE5nQ/J/PCzaU0cKb
kjCpJFqB88nTRvLOrtyzmvfxKm1s7YxgAxMOn88HuRuUQ+5R5OVUbI+pFVXSajwKDJPo
dTqAhhHSUXjujEbUg08hB9aCCxV+PJpj3n1mX1+nb6j9eytN6kyp52mrgwPWbNOvRPbb
s9xdJP7dPq4OT4Pvpq4N/EiJhJynct57CwDV3j6eCavdK8tZ6syqKggpE/iTgqf/x7rk
/5Jg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=kvNuswlK9hsXfoQuDvUPLhH6tDa0cGcPMehJLdbQqwM=;
b=C7H9kfpOYdVNWFKtbv4ohidp/Zb066zd6tcEb+8x8PQ5SG8LBRsV2s5QbzZyutjFqy
tzmPNx2zCYohxG5LFdMVoFdLvhfBsYzl3HyPiiBIoOS4mU7b46TY/wCf/BojFt0eP/nA
Cn7JzwvO3bhFbtxf62o+DPmnTxQb8w5PjI7fXe0TfyyS0bZjnhaZxg/deQaiuCLcSuif
piuyYjhGRKmE+vE7hYGBIV4h0gVdjYpk2KuSmnqS6jJytq4dU+WK1Uxu2css/fENtcPh
L5xioZ28Ew59JRQrpJNE/tX2W9xb/WJ8++/V9HmemOHY6g25CajhSoDwb40RI5//3MfV
PyTA==
X-Gm-Message-State: AO0yUKW7KU/eZhREuxjC/MGl07tgqeBmuEh4afdyqkeULMyXOJoIWGwK
w1vl4RzzPOuRFdADWbHyQuxbuVXdtBA6hv3+OlcVCji9
X-Google-Smtp-Source: AK7set9ASosShWzLlOg3/ssHVRBx1em4M2KoYZwe7nHQl9a5PzjVOs+X+TnLR7YOajbr4GIoNh+ECzS+QL/qurMIzhM=
X-Received: by 2002:a17:906:1653:b0:880:575f:b20c with SMTP id
n19-20020a170906165300b00880575fb20cmr977171ejd.177.1675792023407; Tue, 07
Feb 2023 09:47:03 -0800 (PST)
In-Reply-To: <d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
X-Mailman-Approved-At: Tue, 07 Feb 2023 13:29:20 -0500
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmo_3tgunRswY7LE4mXuDykiPqFqN0W-d1NUbRv=td1G3w@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
 by: Chris Angelico - Tue, 7 Feb 2023 17:46 UTC

On Wed, 8 Feb 2023 at 02:12, Rob Cliffe <rob.cliffe@btinternet.com> 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 starts me
> >> wondering (to go off on a tangent): Should there be a nonlocals()
> >> dictionary?
> > I don't think so, but there might be some value in a dictionary
> > containing all available variables. It would have the same "don't
> > depend on writing" caveats that locals() has (or would be specifically
> > defined as a copy and thus disconnected), so its value would be
> > limited. And it would probably STILL be imperfect, because perfection
> > would require that it be a compiler construct, due to the way that
> > nonlocals are implemented.
> 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
> would be no impact on Python run-time speed if it were only constructed
> on demand.
>

It can't be a built-in function and also be 100% reliable; and if it's
a special compiler construct, its presence in your code would have
semantic impact on all nested functions - even if you never call it:

def func():
x = Obj()
def inner():
if False: get_vars
return inner

x can no longer be disposed of, just in case you call inner and get the vars.

And quite frankly, I don't think this functionality justifies a magic
compiler construct and consequent keyword. But a builtin won't be
reliable.

ChrisA

Re: Evaluation of variable as f-string

<mailman.1781.1675796133.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=21613&group=comp.lang.python#21613

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Evaluation of variable as f-string
Date: Wed, 8 Feb 2023 05:52:14 +1100
Lines: 36
Message-ID: <mailman.1781.1675796133.20444.python-list@python.org>
References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
<mailman.1779.1675784381.20444.python-list@python.org>
<nonlocal-20230207173920@ram.dialup.fu-berlin.de>
<CAPTjJmoXAsPGp9Q5QadwrEWS56RWSFTS9RnUGtOeiQ5=MACaow@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 1WYZ9b2uHyWSa/qbAgFSWg13P2B803az30geL2bv8zsA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=O9hGqVmn;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; '2023': 0.07;
'ram': 0.07; 'python.': 0.08; 'breaks': 0.09; 'construct': 0.09;
'set.': 0.09; 'writes:': 0.09; 'possible,': 0.15; "'':": 0.16;
'(built-in)': 0.16; 'chrisa': 0.16; 'constructed': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'functions.': 0.16; 'print(': 0.16; 'received:209.85.218': 0.16;
'run-time': 0.16; 'subject:string': 0.16; 'subject:variable':
0.16; 'values?': 0.16; 'wrote:': 0.16; 'python': 0.16; 'values':
0.17; 'feb': 0.17; 'to:addr:python-list': 0.20; 'stefan': 0.26;
'local': 0.27; 'function': 0.27; 'output': 0.28; 'attempt': 0.31;
'message-id:@mail.gmail.com': 0.32; 'there': 0.33; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'also,': 0.36; 'those': 0.36;
'received:209.85': 0.37; 'could': 0.38; 'received:209': 0.39;
'wed,': 0.39; 'speed': 0.71; 'quick': 0.77; 'demand.': 0.84;
'rob': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=Q4QEixrvqcuAirxYQJLtRZqEDUemkt81hL+5I21+1gQ=;
b=O9hGqVmnkY9rkcYt9EglBNdz6ysPmEnzIqn7mlQrrzVvc1ig3jJwjOsDbfTBzAwXcP
Oa1Zd8heKeq5NYzH5Sw2bpcjlAmiq3/q9mv+uXV2yKD5I61g3RQ8SRcxCRX3P4EWwlc/
ggxBVrL+GrkpRsDNSR8nK4R7ZBEqFVB1TTmQmTC36JvaM6qwJb/0eUAu4SuxYt5oviEv
z1D5GnkNUlflE+TJa2NubrR+gAUOO9YkGzDUtQ6ZJgUhJJffBgg/ugUbZ7xM59iq3/FO
syx548gkcXsGPzXMh0ZWdhqiA2IDnFopKfqnXjut9mLLm4nasdogv9zVC1nGpFmDeF7B
bm8w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=Q4QEixrvqcuAirxYQJLtRZqEDUemkt81hL+5I21+1gQ=;
b=mdL2SA8+2vzni0GDb3FM+AqR4FcjpahxsZUw9z68nva1Ar06HYZgsEy1j5jYE4cycn
XRQlSzLs9aYRidrSN86iFaCSsIqxVecZUooO9DyyRfflogbMl74q5pRih+qbbS0I0t/o
BZXwk/BJ9qsp8ZS1lSBS2R6gp6kmZu2wfYgrQHFz43g/kENqj69vvu8YvazS/7YRmnQF
lFgrSkxjPTXhY1WMU+faXuf0y445q73hR7XaodIc6r7JFNyRx5i/raGW64BbnQ6IfdHO
ZSpM/hqnGW6CnVZ/4vAeQOU9SlJXFdwQuedTNVF1wmOJgD4+WEcbQWAIzKohdjO96odH
TbGw==
X-Gm-Message-State: AO0yUKVFA+wZkDS6O7L5xAsH14XGmWOjBdah8UZUFZQ7TX3coHTowq5t
iDDjI/cR0iJbONFrxacIhPiGg9IZw3mKxowXgGkoO+pA
X-Google-Smtp-Source: AK7set+z0bMdqIyNJs/xfMV4iy9zMN770IZoXGubvhrxMr/hkOcRpYwnWWveOOiQaEmxNvB6l9tzlr4zbCrACpneCbQ=
X-Received: by 2002:a17:906:1653:b0:880:575f:b20c with SMTP id
n19-20020a170906165300b00880575fb20cmr1023790ejd.177.1675795945585; Tue, 07
Feb 2023 10:52:25 -0800 (PST)
In-Reply-To: <nonlocal-20230207173920@ram.dialup.fu-berlin.de>
X-Mailman-Approved-At: Tue, 07 Feb 2023 13:55:31 -0500
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmoXAsPGp9Q5QadwrEWS56RWSFTS9RnUGtOeiQ5=MACaow@mail.gmail.com>
X-Mailman-Original-References: <tqmcbf$vdl$1@gioia.aioe.org>
<CAPTjJmpKEBbYFxowgm4cDfDn0bmieo9sHLK_sNZh8WcqQ=Wqhw@mail.gmail.com>
<ebb89997-603f-6283-742a-121128e55ae8@btinternet.com>
<CAPTjJmoxero1FVGW8BNB619tS1XA_LOqn=Lnoq3ogw1JPh52Jg@mail.gmail.com>
<8ebc73d2-e14a-b9ad-fa35-5078e5f9fd6c@btinternet.com>
<CAPTjJmqbqNUfRvUt8uwVJLD--faMZVUqTD2LnhD6Cao9Fyx0Yg@mail.gmail.com>
<33f48974-2ddc-67e4-7a79-ef9a758980a9@btinternet.com>
<CAPTjJmpfdvb_yTMu91vNe5Wcb8_u+YO8L8c=w8AFbptj7X7Hiw@mail.gmail.com>
<d9e19a5a-6d9e-d0c0-22f1-731990790541@btinternet.com>
<mailman.1779.1675784381.20444.python-list@python.org>
<nonlocal-20230207173920@ram.dialup.fu-berlin.de>
 by: Chris Angelico - Tue, 7 Feb 2023 18:52 UTC

On Wed, 8 Feb 2023 at 05:30, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
>
> Rob Cliffe <rob.cliffe@btinternet.com> 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
> >would be no impact on Python run-time speed if it were only constructed
> >on demand.
>
> Here's a quick attempt to get local and non-local names as a set.
> It might only work under some implementations of Python.
>
> main.py
>
> set_class = set
>
> def f():
> x = 0
> def g():
> set = set_class()
> for n in g.__qualname__.split( '.' ):
> if n != '<locals>':
> set = set.union( set_class( eval( n ).__code__.co_varnames ))
> print( set )
> g()
> f()
>
> output
>
> {'n', 'set', 'x'}
>

Breaks on wrapped functions. Also, how are you going to get the values
of those variables?

ChrisA


devel / comp.lang.python / To gateway or not to gateway a specific person (was: Evaluation of variable as f-string)

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor