I'm trying to switch from using the os module to pathlib.Path for working with file paths. For some reason, when I construct the path to the feature class (or table) with Path, it fails with
RuntimeError: 'in_table' is not a table or a featureclass
If I simply convert the path to string in the cursor using str(), it works fine. A print() of the path looks normal; not a weird object or something. I get the same behavior with a file geodatabase and Oracle 12c enterprise geodatabase. I also tried using Path.joinpath() instead of the shorthand / but had the same error.
Is there a different way I should be constructing paths?
从pathlib导入路径egdb_conn = r " C: \ GISConnections\user@instance.sde" fc_path = Path(egdb_conn) / "schema.tablename" print(fc_path) print(arcpy.Exists(fc_path)) with arcpy.da.SearchCursor(fc_path, ["OID@"]) as search_cursor: for row in search_cursor: print(row)
BTW, I'm on ArcGIS Pro 2.8
Solved!去解决方案。
It returns a different object type, print works since its __repr__ method returns a string
.... pathlib.WindowsPath
convert to string before arc'ing it
Not surprising, the ArcPy DA module was originally written before pathlib came around. I am guessing Esri will view this as an Enhancement Request to support pathlib.
It returns a different object type, print works since its __repr__ method returns a string
.... pathlib.WindowsPath
convert to string before arc'ing it
Thank you both for sharing your thoughts. I have created a new Python Idea.
Update arcpy cursors to work with paths constructe... - Esri Community