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

Based on my understanding of the ArcGIS path structure, a feature class inside a feature dataset inside a geodatabase can be accessed by the following:


Where Sandwich is the feature dataset and Cheese is the feature class.

In a python script, I want to construct this full path, so that I can check it using arcpy.Exists(x). I have the following variables (pseudocode):

WSpace = C:\Menu\Lunch.gdb\
FDSName = Sandwich
FCName = Cheese

Concatenating WSpace and FDSName gives the correct path to the feature dataset. What I need help with is tacking FCName onto the end. I would think the following code would work, but it renders a space instead of the backslash character:

fullPath = WSpace + FDSName + r"\" + FCName

Instead of r"\", I have also tried "\", and "/", but they all render a space. This seems like a simple syntax problem.

share|improve this question
I would strongly recommend reading the "String literals" section of the Python language reference topic on lexical analysis (how the Python interpreter parses Python source code). – blah238 Feb 7 '13 at 3:34
up vote 9 down vote accepted

Strings, even when marked as r"Raw strings", cannot end with a slash, it needs to be escaped. Should be:

fullPath = WSpace + FDSName + "\\" + FCName

Or better yet, use os.path.join:

fullPath = os.path.join(WSpace, FDSName, FCName)
share|improve this answer
I tried both "\\" and "//": neither worked for me. But I like os.path.join(), that looks promising. – L_Holcombe Feb 7 '13 at 3:36
os.path.join worked perfectly. Thank you for adding that tool to my toolbox. – L_Holcombe Feb 8 '13 at 0:47

I don't know why, but r"\" and r'\' both gave me error. Following one works for me:

workspacePath = r'C:\a.gdb'
datasetName = r'dataset'
featureClassName = r'ofc'
featureClassPath = workspacePath+"\\"+datasetName+"\\"+featureClassName
print featureClassPath

output: C:\a.gdb\dataset\ofc

share|improve this answer
As Jason mentioned, the reason neither r"\" or r'\' works is the single \ escapes the trailing quote, resulting in a syntax error:… – blah238 Feb 7 '13 at 6:22

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.