Skip to content

Instantly share code, notes, and snippets.

@maphew
Created January 17, 2018 21:29
Show Gist options
  • Save maphew/35c4e74b2b547943196229e5f807ec30 to your computer and use it in GitHub Desktop.
Save maphew/35c4e74b2b547943196229e5f807ec30 to your computer and use it in GitHub Desktop.
partial helper for reliably deriving workspace path from input Feature Class path
def parse_path(fc_path):
'''Derive workspace from Feature Class's location
Adapted from http://pro.arcgis.com/en/pro-app/tool-reference/modelbuilder-toolbox/parse-path.htm'''
fc = os.path.basename(fc_path)
dir = os.path.dirname(fc_path)
name = os.path.basename(fc_path).rstrip(os.path.splitext(fc_path)[1])
ext = os.path.splitext(fc_path)[1].lstrip(".")
if ext.lower() == 'gdb':
workspace = fc_path
else:
workspace = dir
return [workspace, dir, fc, name, ext]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment