Jason Camerano gave me this python snippet:
head, sep, tail = arcpy.Describe(parcelFabricLayer).Path.partition(".gdb") workspacePath = head + sep
explanation:
Describe().Path returns the full path that also contains the string ".gdb"
partition separates is using the provided ".gdb" string to:
Anyone has a better method?
Hi Amir.
I do mine a little different. I don't use arcpy to get my workspace path. I find mine takes a lot quicker as it does not have to call arcpy every time, saving a few seconds. With this method you can also use any geodatabase type (.sde, .gdb or .mdb).
accessRoadFc = r"D:\Data\GISData\data\received\Transport.gdb\Routing\AccessRoad" wkspSplit = accessRoadFc.split(".") wkspExt = wkspSplit[1].split("\\")[0] workspace = "{}.{}".format(wkspSplit[0], wkspExt)
For Julian's path example I'd normally use os.
a = r"D:\Data\GISData\data\received\Transport.gdb\Routing\AccessRoad"
os.path.dirname(os.path.dirname(a))
'D:\\Data\\GISData\\data\\received\\Transport.gdb'
In Pro you can use the following:
layer.connectionProperties["connection_info"]["database"]