I have been running into a strange issue with a code I am working on and it only happens when I am working with data formatted like this. This is from a script that uses a Multivalued Parameter. See below:
fc = "'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.ControlValve';'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wFitting';'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wHydrant'"
fclist = fc.split(";")
for each in fclist:
fieldnames = [f.name for f in arcpy.ListFields(each)]
print fieldnames
From this I get the error:
Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\__init__.py", line 1139, in ListFields
return gp.listFields(dataset, wild_card, field_type)
File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\geoprocessing\_base.py", line 346, in listFields
self._gp.ListFields(*gp_fixargs(args, True)))
IOError: "'Database Connections\Prod@GISdb.OSA.sde\Prod.Water\Prod.ControlValve'" does not exist
I am at a loss with this error as it appears quite often. If anyone has any points how to avoid this error I would be extremely grateful!
Solved! Go to Solution.
It turns out it was the single quotes ( ' ) around each file path that was giving me issues. Never knew those would prevent arcpy.Describe and arcpy.ListFields from working 😵
You could use arcpy.describe and .exists to validate the connection file is valid.
maybe some raw formatting on the strings
fc = "r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.ControlValve';r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wFitting';r'Database Connections\\Prod@GISdb.OSA.sde\\Prod.Water\\Prod.wHydrant'"
fclist = fc.split(";")
for each in fclist:
print (each)
fieldnames = [f.name for f in arcpy.ListFields(each)]
print fieldnames
Beyond not using paths that contain spaces, and punctuation (which can cause inconsistent issues).
Set your works space and after parsing the featureclass/feature/table names, do a final check to see if it "exists"
arcpy.env.workspace = "c:/your_path/your.gdb"
# ------ does it exists
if arcpy.Exists("your_fc"):
Do stuff
It turns out it was the single quotes ( ' ) around each file path that was giving me issues. Never knew those would prevent arcpy.Describe and arcpy.ListFields from working 😵