[GIS] Attribute error:’NoneType’ object has no attribute

arcgis-desktoparctoolboxgeoprocessingpython

I tried to run a python script for getting the coordinate system of a feature/shapefile as follow

>>> import arcpy  
>>> from arcpy import env  
>>> env.workspace="D:\data"  
>>> fc="river.shp"  
>>> dsc=arcpy.Describe(fc)  
>>> dsc.spatialReference.Name  
>>> print dsc  

i'm getting following error at line 5

Attributeerror:'NoneType' object has no attribute Name.

Best Answer

Replacing this line:

env.workspace="D:\data"

with:

env.workspace=r"D:\data"

or

env.workspace="D:/data"

or

env.workspace="D:\\data"

should enable it to work but, if you are using ArcGIS 10.1 like me, you will also need to use ".Name" without the capital i.e. ".name".

My working test code:

import arcpy
from arcpy import env
env.workspace=r"C:\temp"
fc="test2.shp"
dsc=arcpy.Describe(fc)
print dsc.spatialReference.name

returns this (as expected):

GCS_GDA_1994