繁体   English   中英

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

[英]variable is not defined, but it is defined as global variable, python

我不断收到错误name 'copyDir is not defined但在我的代码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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM