0
我不斷收到錯誤name 'copyDir is not defined
,但它被定義爲我的代碼中的全局變量。哪裏不對?我在這裏回顧了其他一些類似的帖子,但仍然無法理解這個問題。這裏是我的代碼的開頭部分:變量未定義,但它被定義爲全局變量,python
import arcpy, os, shutil, re
mapIndex = r'C:\Temp\temp.gdb\MapSets_All'
copydDir = r'D:\MapSheetImages\All_Images'
fields = ['FileSpecDir','is_name']
for row in arcpy.da.SearchCursor(mapIndex,fields):
arcpy.env.workspace = row[0]
rstrList = arcpy.ListRasters()
for dir, folders, files in os.walk(row[0]):
try:
if 'CCS27z2e' in folders:
for r in rstrList:
if row[1] in r:
rOrigPath = os.path.join(row[0],r)
rNewPath = os.path.join(copyDir,r)
if not os.path.isfile(rNewPath):
arcpy.AddMessage('now copying '+r)
shutil.copyfile(rOrigPath,rNewPath)
except Exception as e:
print e
arcpy.AddMessage(e)
你的變量是'copydDir',不'copyDir'。錯字 - 'copyDir'沒有定義。 –
該代碼是非常長的除了聲明在最後,所以我沒有發佈它的一切,我會添加該部分它 – KLD
@AndrewDunai哦哇我看不到那些謝謝! – KLD