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!
Great news! There actually already exists an Idea for this here, and it was also implemented finally in ArcGIS Pro 3.7, which released last over two weeks ago.
You can find more information about pathlib in 3.7 at the two links below:
For those like me terminally stuck on older versions (3.1.3, here), I just cast all my pathlib objects to string at the very last second when using them as inputs, so I get nearly all of the benefits of pathlib. Still, it'll be nice A) when I can finally just pass them to arcpy functions and B) can use a python version high enough that it has pathlib's implementation of Walk available. (Both of which will be true whenever I can finally upgrade to 3.7)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.