I have a bunch of feature classes in a geodatabase, and some of them are empty. I want to generate a list of all feature class names, and then remove the names of any feature classes that are empty. For some reason, the (example) code below removes some, but not all of the empty files.
These lines correctly produce a list of all the feature classes:
myDir = r'C:\Projects\geodatabase.gdb'
arcpy.env.workspace = myDir
myfiles = 'MLresult_*'
file_list = arcpy.ListFeatureClasses(myfiles)
If I print the name and the number of records of all files in the list...
for file in file_list:
print(file)
print(arcpy.management.GetCount(file))
The printout is something like:
MLresult_2013
9
MLresult_2018
4
MLresult_2020
0
MLresult_2021
0
Where multiple files are empty (and the counts are all correct). BUT, when I execute these lines...
for file in file_list:
if arcpy.management.GetCount(file)[0] == "0":
file_list.remove(file)
then the list removes some of the "empty" files, but not all, so the list now looks like:
['MLresult_2013', 'MLresult_2018', 'MLresult_2021']
Why would it remove MLresult_2020
, but not MLresult_2021
, when
arcpy.management.GetCount(file)[0] == "0"
Is true for both?
fileB_list
?== "0"
be== 0
?