I was working on a tool the other day. It was something along the lines of :
arcpy.env.workspace = arcpy.management.CreateFileGDB(r"C:\\Documents", "Example")
I got an error
arcpy.env.workspace = arcpy.management.CreateFileGDB(fol, "Example")
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 564, in set_
self[env] = val
~~~~^^^^^
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 640, in __setitem__
ret_ = setattr(self._gp, item, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Object: Error in accessing environment <workspace>
However,
arcpy.env.workspace = str(arcpy.management.CreateFileGDB(fol, "Example"))
works just fine.
CreateFileGDB returns a workspace object. It stands to reason arcpy.env.workspace should be able to consume it.
Please let arcpy.env.workspace take workspace objects.
Workspace objects should also just kinda behave like Path objects. Keeping track of which functions require a concrete class input and which ones need some form of string is a pain. If the concretes could behave like a string when used as an input (e.g. implement __str__ and __fspath__), the consuming function would just need to call arg = str(arg) and the conversion is made.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.