-1

I keep getting this syntax error and don't know why. Brand new to python.

# Opens a feature class from a geodatabase and prints the spatial reference
 
import arcpy
 
featureClass = "C:/Users/Travis Shooks/Documents/script/test.gdb/us_cities"
 
# Describe the feature class and get its spatial reference   
desc = arcpy.Describe(featureClass)
spatialRef = desc.spatialReference

# Print the spatial reference name
print spatialRef.Name

closed as unclear what you're asking by PolyGeo Aug 28 '16 at 19:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Paste here this error log. – dmh126 Aug 28 '16 at 11:38
  • 2
    Welcome to GIS SE. As a new user, please take the Tour. All coding questions should always include the environment, the exact software release(s), the code, and the complete error message (in context to the code snippet). – Vince Aug 28 '16 at 13:17
4

Python is case sensitive. You need to use print spatialRef.name following the SpatialReference documentation.

# Opens a feature class from a geodatabase and prints the spatial reference

import arcpy

featureClass = "C:/Users/Travis Shooks/Documents/script/test.gdb/us_cities"

# Describe the feature class and get its spatial reference   
desc = arcpy.Describe(featureClass)
spatialRef = desc.spatialReference

# Print the spatial reference name
print spatialRef.name

As a side note, you can shorten this to a one-liner if you prefer:

import arcpy

featureClass = "C:/Users/Travis Shooks/Documents/script/test.gdb/us_cities"

print arcpy.Describe(featureClass).spatialReference.name

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