我是Python的新手。阅读课堂新材料,我不得不复制并粘贴一些例子,看看事情是如何运作的。因此,我在“网络模型中的循环”主题下复制并粘贴了此网站(https://www.e-education.psu.edu/geog485/node/54)中的代码。 这是我的:
import arcpy
try:
arcpy.env.workspace = "C:\Users\dan and kathryn\Desktop\school\programming\Lesson1"
fcList = arcpy.ListFeatureClasses()
for featureClass in fcList:
arcpy.CopyFeatures_management (featureClass, "C:\Users\dan and kathryn\Desktop\school\programming\Lesson 2\PracticeData/" + featureClass)
except:
print "Script failed to complete"
print arcpy.GetMessages(2)
这是错误消息:
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonWin\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\dan and kathryn\Desktop\loops_gis.py", line 1, in <module>
import arcpy
File "C:\Users\dan and kathryn\Desktop\arcpy.py", line 5, in <module>
desc = arcpy.Describe(featureClass)
AttributeError: 'module' object has no attribute 'Describe'
联系我的老师,他写了代码并发给我,但一切都匹配。所有反斜杠,缩进,除文件夹位置以外的所有内容。不知道发生了什么,但他怀疑这个问题超出了我在代码中编写的问题。
我已经不得不改变pythonWin中的site-packages文件夹,它现在包含:
# .pth file for the PyWin32 extensions
win32
win32\lib
Pythonwin
C:\Program Files (x86)\ArcGIS\Desktop10.1\bin
C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Scripts
不确定发生了什么或为什么'Describe'甚至会出现问题
答案 0 :(得分:1)
每当写入路径字符串时,请使用r“带反斜杠的路径”。它将解决反斜杠和正斜杠的问题。需要连接路径时,请使用“ os”模块。
答案 1 :(得分:0)
继承人我有所改变(所有在反斜杠中,我都不知道):
arcpy.env.workspace =“C:/ Users / dan and kathryn / Desktop / school / programming / Lesson1”
和
arcpy.CopyFeatures_management(featureClass,“C:\ Users \ dan and kathryn \ Desktop \ school \ programming \ Lesson 2 \ PracticeData /”+ featureClass)