Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

MS-DOS, you can't live with it, you can live without it. -- from Lars Wirzenius' .sig


devel / comp.lang.python / Re: fCONV_AUSRICHTG is not defined - Why?

SubjectAuthor
* Re: fCONV_AUSRICHTG is not defined - Why?MRAB
`- Re: fCONV_AUSRICHTG is not defined - Why?Greg Ewing

1
Re: fCONV_AUSRICHTG is not defined - Why?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.niel.me!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: fCONV_AUSRICHTG is not defined - Why?
Date: Tue, 7 Nov 2023 19:10:07 +0000
Lines: 66
Message-ID: <mailman.198.1699384395.3828.python-list@python.org>
References: <e341ea45-5d8b-da2a-00a1-c2a4c65386de@frerich.eu>
<a5ac87ee-81ad-4b9f-a05e-14bb903671a7@DancesWithMice.info>
<b50dc492-90e3-401a-8d62-b0911c459f7c@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de t2SJlP+Zvs3fwwbEMoIpgAoWlzVBeDR/9Fw1YllMtDEQ==
Cancel-Lock: sha1:/7Lb+oViE84yXVVHVgnlCU8191s= sha256:9Qg/NIBncC0kT8UbQb24OF+qNVJXpu3SpIdpz/SmUHo=
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=cRnpvVZj;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Why': 0.07;
'utf-8': 0.07; '(python': 0.09; 'from:addr:python': 0.09;
'happens.': 0.09; 'received:192.168.1.64': 0.09; 'subject:not':
0.09; 'import': 0.15; '-*-': 0.16; 'definitions': 0.16;
'encoding:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16;
'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:84.93': 0.16; 'received:84.93.230': 0.16;
'received:84.93.230.227': 0.16; 'received:plus.net': 0.16;
'script,': 0.16; 'subject:skip:f 10': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; "i've": 0.22; 'idea': 0.24; '11,':
0.26; 'header:User-Agent:1': 0.30; 'module': 0.31; 'extract':
0.32; 'python-list': 0.32; 'received:192.168.1': 0.32; 'but':
0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'change': 0.36;
'lists': 0.37; 'missing': 0.37; "skip:' 10": 0.37; 'class': 0.37;
'received:192.168': 0.37; 'file': 0.38; 'both': 0.40; 'something':
0.40; 'detail': 0.61; 'in:': 0.64; 'shows': 0.67; 'implemented':
0.76; 'happens': 0.84; 'skip:" 50': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1699384207; bh=7GHWX8n0zEIlQOrluAul26WYPiXYEmHTJqavunb3Ceo=;
h=Date:Subject:To:References:From:In-Reply-To;
b=cRnpvVZjWPoaEuanG5uzQs/nq4xDZlWyFaeeOVrB7clU02IRM3IfdebvR+Yio+dNj
Dcxsou9UZUKLdpwhFnEO7XpiaDLGguODuTQrQ/bkYo7oL5c6EmMzN/5Z9nGWqVMK1p
WDOX5tx6jaRQ3qfO2MrYct+mqBWJF+JiQ9qVW3FOBIQgAnGP3wgvGQmHlXqxefYgCh
jbwQKQcGHhXcYr3ABgar8AtTiqaahfcddQ+ApTk76rLzphtezs7A3sSHU1ohA1O6yw
qVHl0VPEa938LIZ84sI8zYS/pIJBaTNQ4cM/EA/DDxSCnC0WC43Nb3vMkxh9US0iLk
4AhwrxpcEf/oQ==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=XaWaca15 c=1 sm=1 tr=0 ts=654a8b8f
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=EybDFLOw2FvwiyadjuQA:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <a5ac87ee-81ad-4b9f-a05e-14bb903671a7@DancesWithMice.info>
X-CMAE-Envelope: MS4xfNQpxOiAZbBzCEwHQG4fM5mWGyc12UUZk7OeCid5xp1KN853l9iYr12M3plj1IJyMnWCD0CcAumHy+XyTinqnGDHuKGOuIXtHU2ITKoun9J4RRuCenuh
lfnkp2wu3//V2sbLTKdI3InrjA++vtYrDRy8x1WSI95+E3CsOYLoWsiWSV8dorxD0N0maXHIEboTG54W2Uukhp1vYAGzwkc8Wd8=
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: <b50dc492-90e3-401a-8d62-b0911c459f7c@mrabarnett.plus.com>
X-Mailman-Original-References: <e341ea45-5d8b-da2a-00a1-c2a4c65386de@frerich.eu>
<a5ac87ee-81ad-4b9f-a05e-14bb903671a7@DancesWithMice.info>
 by: MRAB - Tue, 7 Nov 2023 19:10 UTC

On 2023-11-07 18:30, dn via Python-list wrote:
> On 08/11/2023 06.47, Egon Frerich via Python-list wrote:
>> I've no idea why this happens. In a module there are lists and definitions:
> ...
>
>>     ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in Felder])
>>   File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 90,
>> in <listcomp>
>>     ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in Felder])
>> NameError: name 'fCONV_AUSRICHTG' is not defined
>>
>> You see "Felder" and with "0 0 3 4" the correct value 4 for
>> fCONV_AUSRICHTG. But there is the NameError.
>>
>> What does <listcomp> mean? Is there a change from python2 to python3?
>
> Works for me (Python 3.11 on Fedora-Linux 37)
> - both as a script, and simple/single import.
>
> What happens when you extract the second dimension's definitions into a
> module of their own, and import that (with/out less-sophisticated join)?
>
The missing detail is this line from the traceback:

File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 11,
in <module>
class GUIcfg:

Here's a small example that shows the problem:

----8<----
#!python3.11
# -*- encoding: utf-8 -*-

class Test:
hello = "hello"
print(hello)
print([[zero] for _ in range(4)])
----8<----

and its traceback:

----8<----
hello
Traceback (most recent call last):
File "C:\Projects\regex3\test_clipboard.py", line 4, in <module>
class Test:
File "C:\Projects\regex3\test_clipboard.py", line 7, in Test
print([zero for _ in range(4)])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Projects\regex3\test_clipboard.py", line 7, in <listcomp>
print([zero for _ in range(4)])
^^^^
NameError: name 'zero' is not defined
----8<----

'zero' is visible in:

print(hello)

but not in:

print([zero for _ in range(4)])

Something to do with how scoping is implemented in comprehensions?

Re: fCONV_AUSRICHTG is not defined - Why?

<kr0369F994nU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: fCONV_AUSRICHTG is not defined - Why?
Date: Wed, 8 Nov 2023 13:31:03 +1300
Lines: 22
Message-ID: <kr0369F994nU1@mid.individual.net>
References: <e341ea45-5d8b-da2a-00a1-c2a4c65386de@frerich.eu>
<a5ac87ee-81ad-4b9f-a05e-14bb903671a7@DancesWithMice.info>
<b50dc492-90e3-401a-8d62-b0911c459f7c@mrabarnett.plus.com>
<mailman.198.1699384395.3828.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net DxZsH3dvbl9823jd8Nkr6A9MfkT6EY9T7f5MahTm3xHaB5glss
Cancel-Lock: sha1:4M2OBmPeflWjKWdHLimnSX8q4eg= sha256:Ft7Xjcr5g8CWiInNAHnGdE6V93Lj++Dtx8tTpLV9bso=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.198.1699384395.3828.python-list@python.org>
 by: Greg Ewing - Wed, 8 Nov 2023 00:31 UTC

On 8/11/23 8:10 am, MRAB wrote:
> Something to do with how scoping is implemented in comprehensions?

Yes, together with the way class scopes work during class construction.

Behind the scenes, the body of a listcomp happens to be implemented
as a nested function.

Usually you don't notice this, but while a class is being built,
its scope doesn't count as an enlosing scope for functions defined
within the class.

This is necessary, otherwise all of a class's attributes would be
visible inside its methods, which isn't what we want. However, it
leads to some odd corner cases, such as this one.

There are various ways you could work around this. I would suggest
moving the offending code outside the class and qualifying the
constants it uses with the class name.

--
Greg

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor