Problem running a FOR loop

Steve Gronicus at SGA.Ninja
Sun Aug 30 04:55:49 EDT 2020


Compiles, no syntax errors however, line 82 seems to run only once when the
FOR loop has completed.
Why is that?  All fields are to contain the specifications, not just the
last one.

Steve
----------------------------------------------------------------------------
------------------------------
ThisList = ["start"]
    
#===============================================================
def FillTheList():
   x=0
   ThisList = []
   with open("Specifications.txt", 'r') as infile:
     for lineEQN in infile: # loop to find each line in the file for that
dose
         if lineEQN[0:1] == "-":
           ListItem = lineEQN[1:6].strip()
           ThisList.append(ListItem)

   return(ThisList)

#====================================================================
    
def EditDataByForm():

    import tkinter as tk
    from tkinter import ttk
    import sys

    window = tk.Tk()

    window.title("Python Tkinter Text Box")
    window.minsize(700,700) #height, width
    
    #===============================================================
    def GetLineByItem(DataType):  #get line by item in column 3 - 5
        #print("DataType = " + DataType)
        DataLetter = DataType[0:1]

        if DataLetter.isupper(): # == "Specs":
            FileToBeEdited = "Specifications.txt"
        else:
            FileToBeEdited = "DataSpecifications.txt"
        
        with open(FileToBeEdited, 'r') as infile:
             for lineEQN in infile: # loop to find each line in the file for
that dose        
               if ((lineEQN[1:2]== DataLetter)):
                   A = lineEQN[1:46]            # Whole Line
                   a = lineEQN[34:46].strip()   # Just the Data
   #     print("A = " + A )
   #     print("a = " + a)
          
        return(A, a)
    
    #===============================================================
    
    def ClickSubmit():
        window.destroy()
    #===============================================================

    label = ttk.Label(window, text = "Enter the new readings")
    label.grid(column = 1, row = 1)
     
    ThisList = FillTheList()
    x = 3  # Allows for two rows at the top of the form used for headers
    y = 0  # Scans the datafile to fill the list
    
    for lineItem in range(len(ThisList)):
    
         SpecLine, Spec = GetLineByItem(ThisList[y])
         OldSpec = Spec
         #print("OldSpec = " + OldSpec)
         NewSpec = " "

         SVRlabel = ttk.Label(window, text = SpecLine + "  "*5)
         SVRlabel.grid(column = 1, row = x)
                     
         NewSpec = tk.StringVar()
         SVRCodeEntered = ttk.Entry(window, width = 15, textvariable =
NewSpec)
         SVRCodeEntered.grid(column = 2, row = x, pady = 15)

         print("x , y = " + str(x) + ", " + str(y))
         
         print("OldSpec2 = <" + OldSpec + "> ") #Use of <> show spaces if
any

         #81 The next line seems to run only once at the end of the FOR loop
<<<<<<<<<<<<<<
         SVRCodeEntered.insert(0, OldSpec)

         SVRCodeEntered.focus_set()

         x += 1 
         y += 1
    #===============================================================
    button = ttk.Button(window, text = "Submit", command = ClickSubmit)
    button.grid(column= 2, row = 15)

    window.mainloop()  
------------------------------------------------------
Specifications.txt.  This will align when using Notepad++.

A LTD Last Time Date              2020-08-29 00:55:18.610102       ##   
 B LDL Last Dose Line              2020-08-29 00:55:18.610102       ##   
 C LLL Last LTD line               2020-08-29 00:55:18.610102       ##   
 D LTD Last Time Date              2020-08-29 00:55:18.610102       ##   
 -
-E MSN Monitor Serial Number       JNGY263-T4464                    ##   
 -
-F TSL TestStrip Lot Number        45001 82990                      ##   
-G SED Strip Expire Date           2021-05-31                       ##   
 -
-H SSC Sensor Sequence Code        71                               ##   
-I SCN Sensor Code Number          G03                              ##   
-J SSN Sensor Serial Number        2021-01-31                       ##   
-K SDE Sensor Date to Expire       2021-01-31                       ##   
-L SDN Sensor Day Number           12                                ##   
-M FDS First Date for Sensor       Fri Aug 17, 2020 09:34           ##
 -
-N IDT Insulin Dose Total          450                              ##

 O DTD Data Time Date              Fri Aug 07, 2020 21:30           ##   
 P PTD Previous Time Date          Thu Nov 27, 1952 14:30           ##   
 -
 Q HL1 Half Life 1                 1                                ##

 R HL2 Half LIfe 2                 2                                ##   
 S HL3 Half Life 3                 3                                ##
 T TIL Total Insulin Layer         25                               ##
----------------------------------------------------------------------------
-------------------
Footnote:
The power company in Utah has built the Sisyphus train.  When there is a
surplus of available energy from their massive collection of solar cells,
they use it to drive a train up a hill.  At night when the need power, they
ease the train down to generate energy to fill the gap.

- 



More information about the Python-list mailing list