AnsweredAssumed Answered

OSError: "[list of filenames]" does not exist

Question asked by jbelanger on Jul 28, 2020
Latest reply on Jul 29, 2020 by jbelanger

Hello,

 

Apologies in advance if this is a duplicate question. This question seems to be slightly similar, but I think mine is more basic. I am trying to run a simple for loop in jupyter notebooks to iterate through tables in a gdb with arcpy.AlterField_management and update non-required field names with the name of the table. However, when running this operation I get an OSError: "[list of filenames]" does not exist. I got the same error when running the script in an arcgis toolbox. My code and the error message are below.

 

I saw in this stack overflow question that it might be an issue with my arcpy site package, but I don't know how to rectify if that were the issue.

 

Thanks!

Jo

 

------
import arcpy, os, sys
from arcpy import env

 

arcpy.env.overwriteOutput = True

 

# Set the workspace directory - make sure it's the copied gdb and not the original, in case you mess up
arcpy.env.workspace = r"P:\AFG\GEO\Team\Projects\Shock_Vulnerability\NTL\NTL_201801_202001_AFG_proj_zonalst_copy.gdb"

 

# Get the list of the zonal stats tables to process
tables = arcpy.ListTables(wild_card="*AFG_proj_zonalst", table_type="ALL")
print (tables)

 

# iterate through the tables in the gdb and update field names with the file names
for table in tables:
      print ("processing: " + table)
      # print field names
      # iterate through field names in table
      for fname in [f.name for f in arcpy.ListFields(tables, wild_card="", field_type="ALL") if not f.required]:
            print(fname)
            arcpy.AlterField_management(table, f.name, f.name+"_%Name%")
            print(fname)
-------
['NTL_QN_202001_AFG_proj_zonalst', 'NTL_201912_AFG_proj_zonalst', 'NTL_201911_AFG_proj_zonalst', 
'NTL_201910_AFG_proj_zonalst', 'NTL_201909_AFG_proj_zonalst', 'NTL_201908_AFG_proj_zonalst',
'NTL_201907_AFG_proj_zonalst', 'NTL_201906_AFG_proj_zonalst', 'NTL_201905_AFG_proj_zonalst',
'NTL_201904_AFG_proj_zonalst', 'NTL_201903_AFG_proj_zonalst', 'NTL_201902_AFG_proj_zonalst',
'NTL_201901_AFG_proj_zonalst', 'NTL_201812_AFG_proj_zonalst', 'NTL_201811_AFG_proj_zonalst',
'NTL_201810_AFG_proj_zonalst', 'NTL_201809_AFG_proj_zonalst', 'NTL_201808_AFG_proj_zonalst',
'NTL_201807_AFG_proj_zonalst', 'NTL_201804_AFG_proj_zonalst', 'NTL_201801_AFG_proj_zonalst',
'NTL_201806_AFG_proj_zonalst', 'NTL_201802_AFG_proj_zonalst', 'NTL_201805_AFG_proj_zonalst',
'NTL_201803_AFG_proj_zonalst', 'NTL_202001_AFG_proj_zonalst'] processing: NTL_QN_202001_AFG_proj_zonalst
---------------------------------------------------------------------------OSError             
Traceback (most recent call last)<ipython-input-14-596e9c744258> in <module>    
16
     # print field names    
17
     # iterate through field names in table
---> 18     for fname in [f.name for f in arcpy.ListFields(tables, wild_card="", field_type="ALL") if not f.required]:    
19
             print(fname)    
20
             arcpy.AlterField_management(table, f.name, f.name+"_%Name%")C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py in ListFields(dataset, wild_card, field_type)  
1131
  
1132
         * String:   Only field types of String are returned."""
-> 1133     return gp.listFields(dataset, wild_card, field_type)  
1134
  
1135
@_gptooldoc(None, [[["FeatureLayer", "Table", "TableView", "Dataset", "FeatureDataset"], "", "", ""]])C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in listFields(self, *args)   
346
         from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject   
347
         return convertArcObjectToPythonObject(
--> 348                     self._gp.ListFields(*gp_fixargs(args, True)))   
349
     def listIndexes(self, *args):   
350
         """GP function ListIndexes"""
OSError: "['NTL_QN_202001_AFG_proj_zonalst', 'NTL_201912_AFG_proj_zonalst',
'NTL_201911_AFG_proj_zonalst', 'NTL_201910_AFG_proj_zonalst', 'NTL_201909_AFG_proj_zonalst', 'NTL_201908_AFG_proj_zonalst',
'NTL_201907_AFG_proj_zonalst', 'NTL_201906_AFG_proj_zonalst', 'NTL_201905_AFG_proj_zonalst', 'NTL_201904_AFG_proj_zonalst',
'NTL_201903_AFG_proj_zonalst', 'NTL_201902_AFG_proj_zonalst', 'NTL_201901_AFG_proj_zonalst', 'NTL_201812_AFG_proj_zonalst',
'NTL_201811_AFG_proj_zonalst', 'NTL_201810_AFG_proj_zonalst', 'NTL_201809_AFG_proj_zonalst', 'NTL_201808_AFG_proj_zonalst',
'NTL_201807_AFG_proj_zonalst', 'NTL_201804_AFG_proj_zonalst', 'NTL_201801_AFG_proj_zonalst', 'NTL_201806_AFG_proj_zonalst',
'NTL_201802_AFG_proj_zonalst', 'NTL_201805_AFG_proj_zonalst', 'NTL_201803_AFG_proj_zonalst', 'NTL_202001_AFG_proj_zonalst']" does not exist

Outcomes