变量未定义,但定义为全局变量,python

variable is not defined, but it is defined as global variable, python

我一直收到错误 name 'copyDir is not defined 但它在我的代码中被定义为全局变量。怎么了?我在这里查看了一些与此类似的其他帖子,但仍然无法理解这个问题。这是我的代码的开头部分:

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 = r'D:\MapSheetImages\All_Images'

应该是:

copyDir = r'D:\MapSheetImages\All_Images'