Re: fCONV_AUSRICHTG is not defined - Why?

2023-11-08 Thread Egon Frerich via Python-list


Am 07.11.23 um 20:10 schrieb MRAB via Python-list:

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 
 ["%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  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 
 class GUIcfg:

You are right. The list comprehension has to be outside the class. The 
scope rules have been changed python2 and python3.


Egon




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



--
https://mail.python.org/mailman/listinfo/python-list


fCONV_AUSRICHTG is not defined - Why?

2023-11-07 Thread Egon Frerich via Python-list

I've no idea why this happens. In a module there are lists and definitions:

    Felder = [
    # Name   lg1  lg2 typ   Ausrichtung Holen Prüfen Prüfvorg
    ["Jahr", 4, 5, "u", "", "right", "center"],
    ["Monat", 2, 5, "u", "", "right", "center"],
    ["Tag", 2, 3, "u", "", "right", "center"],
    ["Belegnr", 5, 7, "s", "", "right", "center"],
    ["Bank", 2, 4, "u", "", "center", "center"],
    ["Art", 2, 3, "u", "", "center", "center"],
    ["Aufg", 2, 4, "u", "", "center", "center"],
    ["Text", 25, 25, "s", "-", "left", "left"],
    ["Ergänzung", 12, 12, "s", "-", "left", "left"],
    ["Betrag", 13, 13, "s", "", "right", "right"],
    ["W", 1, 2, "s", "", "center", "center"],
    ["WBetrag", 7, 7, "s", "", "right", "right"],
    ["Kurs", 6, 6, "s", "", "right", "right"],
    ]
    "Reihenfolge in der Dimension 1"
    (
    fJAHR,
    fMONAT,
    fTAG,
    fBELEGNR,
    fBANK,
    fART,
    fAUFGABE,
    fTEXT,
    fTEXTERG,
    fBETRAG,
    fWAEHRUNG,
    fBETRAGinWAEHRUNG,
    fUMRECHNUNGSKURS,
    ) = list(range(13))
    "Reihenfolge in der Dimension 2"
    (
    fNAME,
    fLG1,
    fLG2,
    fTYP,
    fCONV_AUSRICHTG,
    fENTRY_AUSRICHTG,
    fTEXT_AUSRICHTUNG,
    fHOLFUNKT,
    fPRUEFFUNKT,
    fPRUEF_ARG,
    ) = list(range(10))


Two lines with  test statements follow and the statement which produces 
an error:


    print(Felder)
    print(fJAHR, fNAME, fTYP, fCONV_AUSRICHTG)
    akette = "%" + "%".join(
    ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in 
Felder])


The traceback shows:

$ python3 testGeldspurGUI.py
[['Jahr', 4, 5, 'u', '', 'right', 'center'], ['Monat', 2, 5, 'u', '', 
'right', 'center'], ['Tag', 2, 3, 'u', '', 'right', 'center'], 
['Belegnr', 5, 7, 's', '', 'right', 'center'], ['Bank', 2, 4, 'u', '', 
'center', 'center'], ['Art', 2, 3, 'u', '', 'center', 'center'], 
['Aufg', 2, 4, 'u', '', 'center', 'center'], ['Text', 25, 25, 's', '-', 
'left', 'left'], ['Ergänzung', 12, 12, 's', '-', 'left', 'left'], 
['Betrag', 13, 13, 's', '', 'right', 'right'], ['W', 1, 2, 's', '', 
'center', 'center'], ['WBetrag', 7, 7, 's', '', 'right', 'right'], 
['Kurs', 6, 6, 's', '', 'right', 'right']]

0 0 3 4
Traceback (most recent call last):
  File "/home/egon/Entw/Geldspur/geldspur/testGeldspurGUI.py", line 15, 
in 

    from tests.testU2 import testU2
  File "/home/egon/Entw/Geldspur/geldspur/tests/testU2.py", line 9, in 


    from gui.GUI_Konfig import GUIcfg
  File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 11, 
in 

    class GUIcfg:
  File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 90, 
in GUIcfg

    ["%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 

    ["%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  mean? Is there a change from python2 to python3?

Egon



--
https://mail.python.org/mailman/listinfo/python-list