arcpy.da.SearchCursor RuntimeError: cannot open '.shp'

arcpy在使用arcpy.da.SearchCursor讀取shp時報錯RuntimeError: cannot open '.shp',代碼如下:

#coding:utf8
import arcpy

path=r'D:\work\data\temp\test.shp'
with arcpy.da.SearchCursor(path,'FID') as rows:
    print rows

錯誤信息:

Traceback (most recent call last):
File "D:/temp/test.py", line 11, in <module>
with arcpy.da.SearchCursor(path,'FID') as rows:
RuntimeError: cannot open 'D:\work\data\temp\test.shp'

解決方法:

在這句之前如果設置了arcpy.env.workspace 或者執行了與文件路徑相關的arcpy的函數之後就不報錯了。例如:

arcpy.env.workspace = r'D:\work\data\temp'

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章