pathlib seems to be the preferred method for working with system paths in Python 3. We've started using it in place of `os.path` in our office recently and really like it. However, we've run into problems with using it with arcpy. For example:
workspace = pathlib.Path('C:\some path') \ 'anotherfolder' \ 'connection.sde'
with arcpy.EnvManager(workspace=workspace):
passThrows this error: "RuntimeError: Object: Error in accessing environment <workspace>"
To work around this, we end up wrapping all of our Path object with str(). For example:
workspace = str(pathlib.Path('C:\some path') \ 'anotherfolder' \ 'connection.sde')
with arcpy.EnvManager(workspace=workspace):
passIt would be great if arcpy (Pro version) handled these Path objects natively!
Per the arcpy team at the Dev Summit this is releasing with 3.7. All tools will work with path objects as inputs. An env setting needs to be set for outputs.
Congratulations! The idea made its way into the software - geoprocessing tools and ArcPy functionality support Python pathlib.Path objects, allowing paths to be passed directly without being converted to strings.
Learn more about using pathlib.Path with geoprocessing tools
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.