Skip to content Skip to sidebar Skip to footer

Error: None-type Error During Iteration With Python

I have created a working code to convert GPX files to feature classes in ArcGIS. Unfortunately I have ran into a file that is either corrupted or encrypted (I really don't know). I

Solution 1:

So the problem was that arcpy.ListFiles() suddenly stopped working. Once I fixed that (somehow) I ran into the error that the GPX feature already had the new field and could not add another by the same name because the convertedfile object still held the information for the file that last passed when the corrupted file was being iterated over. To fix this, I put the arcpy.AddField() and arcpy.CalculateField() within the try. Now the code works and passes over the corrupted file after giving me the message that it failed to convert using arcpy.AddMessage() and only merges the successfully converted files. The new try and except code looks like this:

outfile = outputGdb + "\\" + fileType + "_" + featureName

try:
    # Now convert
    arcpy.GPXtoFeatures_conversion(inGPX,outfile)
    convertedfile = outfile

    # Add a new field and populate it with the gpx file name to use for the join later
    arcpy.AddField_management(convertedfile, "Original_GPX_File", "DOUBLE", 9, "", "", "Original_GPX_File", "NULLABLE", "REQUIRED")
    arcpy.CalculateField_management(convertedfile, "Original_GPX_File", featureName)
    fcList.append(convertedfile)

except:
    arcpy.AddMessage("File " + featureName + " could not be converted")

# The counter so you know where you are in the iteration
if i%250 == 0:
    arcpy.AddMessage(str(i) + " files have been converted at " + str(datetime.datetime.now()))
i += 1

Post a Comment for "Error: None-type Error During Iteration With Python"