AnsweredAssumed Answered

Fill table with update cursor? array?

Question asked by JB1234510 on Sep 20, 2019
Latest reply on Sep 22, 2019 by JB1234510

Hello,

I have problems to update two attribute fields with values created in the following code. The insert cursor works well but with the update cursor I get a error message. Are there any other ways to fill a table with values?

 

Error message:

line 60, in UpdateFields
    cursor.updateRow([row])
StopIteration: iteration not started

 

# -*- coding: cp1252 -*-
import arcpy, os

arcpy.env.overwriteOutput = True

myPath = r"R:\Daten\geo_daten\Arten\Fledermaeuse\AltDaten"
out_path_table = r"C:\temp4\Geodatenbestand.mdb"
out_name_table = "Geodatenbestand"
template_table = r"C:\temp4\Geodatenbestand.mdb\Geodatenbestand_Template"
inTable = os.path.join(out_path_table, out_name_table)
inTableL = "Table_Layer"

MyList1 = list()
MyList2 = list()

# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()

class Geodatenbestand(object):

    def __init__(self):

        self.myPath = myPath      

    def SearchFiles(self):
       
        SHPCounter = 0
               
        for path, dirs, files in os.walk(myPath):
            for file in files:
                if file.lower().endswith('.shp'):
                    print path + "\\" + file
                   
                    SHPCounter += 1
                    print SHPCounter
                   
                    accessTime = os.path.getatime(os.path.join(path, file)) # last access time
                   
                    actualTime = time.time()

                    hoursPassed = """{}""".format(int((actualTime - accessTime)/3600))

                    path1 = path.decode(stdout_encoding)
                    file1 = file.decode(stdout_encoding)
                    print file1
                   
                    cursor = arcpy.da.InsertCursor(inTable, ['PathFile'])
                    cursor.insertRow([path1 + "\\" + file1])

                    MyList1.append(file1)
                    MyList2.append(hoursPassed)

    def UpdateFields(self):
       
        print MyList1
                       
        with arcpy.da.UpdateCursor(inTable,["File"]) as cursor:
            for row in MyList1:
               
                cursor.updateRow([row])

        print MyList2
       
        with arcpy.da.UpdateCursor(inTable,["h_not_used"]) as cursor:
            for row in MyList2:
               
                cursor.updateRow([row])
             

    def CreateTable(self):
       
        if arcpy.Exists(inTable):
            arcpy.Delete_management(inTable)
        arcpy.CreateTable_management(out_path_table, out_name_table, template_table)

       
if __name__ == '__main__':

    MyClass = Geodatenbestand()
   
    MyClass.CreateTable()
    MyClass.SearchFiles()
    MyClass.UpdateFields()
   


Outcomes