我需要帮助确定为什么在更改工作区位置后我的脚本无法运行

 收藏

我最近开始在家工作,我的脚本运行缓慢,因此我想将其转换为在我的桌面上运行,但我一直遇到错误,我不知道为什么。

这是我脚本的一部分。我将输入目录和os.chdir更改为我的计算机上一直运行到FCS中FC的位置。

对于FC中的FC: TypeError:“ NoneType”对象不可迭代

谁能看到我缺少的内容以允许其运行循环?非常感谢

############常量#################

导入日期时间 导入日志 导入字符串 导入os.path 导入系统 导入arcgisscripting gp = arcgisscripting.create(9.3)

设置必要的产品代码

gp.SetProduct(“ ArcInfo”)

加载所需的工具箱...

gp.AddToolbox(“ C:/ Program Files(x86)/ArcGIS/Desktop10.6/ArcToolbox/Toolboxes/Data Management Tools.tbx”) gp.AddToolbox(“ C:/程序文件(x86)/ArcGIS/Desktop10.6/ArcToolbox/Toolboxes/Analysis Tools.tbx”)

日志将保存到当前脚本位置

uniq_filename = str(datetime.datetime.now()。date())+'_'+ str(datetime.datetime.now()。time())。replace(':','。') 打印uniq_filename uniq_filename_log ='GPS_Processing_'+ uniq_filename +'。' +“日志” 打印uniq_filename_log

logging.basicConfig(filename = uniq_filename_log,level = logging.DEBUG) logging.info('uniq_filename_log')

打印'##开始00_GPSDataProcessing_Survey脚本##'

可以将其替换为要列出所有子目录的目录的文件路径

INPUT_DIRECTORY ='G:/ WTMA / 2_YCA_Operations / Field Teams / GPS DATA / 2_DataDrop_Processing'

需要更改此命令,以便将其设置为Windows文件路径,而不是python脚本的位置-可能是'os'。命令。

os.chdir(r“ G:/ WTMA / 2_YCA_Operations / Field Teams / GPS DATA / 2_DataDrop_Processing”)

子目录列表

print(“ \ n我们仅列出当前目录中的目录-”) directorys_in_curdir =过滤器(os.path.isdir,os.listdir(os.curdir)) 打印(directories_in_curdir)

使用子目录列表在“ for循环”中循环浏览

对于directory_in_curdir中的sub_dir:     #将子目录追加到输入目录路径     CurrentWS = INPUT_DIRECTORY +'\'+ sub_dir +'\ shp'     打印CurrentWS     gp.Workspace = CurrentWS

# List function returns a Python list

#

fcs = gp.ListFeatureClasses()

print fcs


# Step through a Python list using a while loop

#

for fc in fcs:


    # Remove file extension from filename
    fcabbrev = fc.rstrip('.shp')
    print fc
    print fcabbrev
    logging.info(fc)
    logging.info(fcabbrev)

    # Remove first 9 characters (the date) from filename to give remainder of filename (GPS #, Owner Initials, Job type)

    fn_rest = fcabbrev[9:]
    print fn_rest
    logging.info(fn_rest)
    #expression = fn_rest

    gp.toolbox = 'management'

    # Process: Add Field - Owner
    # AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
    gp.AddField(fc, "Owner", "Text", field_length=50)
    print 'Owner field created'


        #"'value'" to populate with free text
        #   str(value)
        #'"' + value + '"' to populate with the result of former process (in this case, fcabbrev)

    # Process: Calculate Field - Owner
    # CalculateField_management (in_table, field, expression, {expression_type}, {code_block})
    gp.CalculateField(fc, "Owner", '"' + fn_rest + '"', "PYTHON_9.3")
    print 'Owner field calculated'

它继续前进,但给一个想法

回复