Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to set workspace from input Feature Class ? is there an attribute of the source GDB for a feature class ? some times the FC is in a dataset and some time it isn't, How can i get the path of source GDB for setting workspace when the input is dynamic ?

share|improve this question
up vote 10 down vote accepted

Use the catalogPath property of the Describe object.

For example:

dirname = os.path.dirname(arcpy.Describe(feat_class).catalogPath)
desc = arcpy.Describe(dirname)
if hasattr(desc, "datasetType") and desc.datasetType=='FeatureDataset':
    dirname = os.path.dirname(dirname)
share|improve this answer
the catalog path function gives the path with the dataset, for setting workspace i need the path to the GDB only (without the data set) – Geog Aug 31 '14 at 8:25
@Geog Luke is correct. os.path.dirname() extracts the workspace out of the full path. – radouxju Aug 31 '14 at 8:53
@Geog Use os.path.dirname twice. See edit. – Luke Aug 31 '14 at 8:58
You can also try using the path property of the Describe object: – amarinel Apr 28 at 5:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.