在arcpy搜索游标where子句中使用撇号麻烦

时间:2014-05-15 22:30:17

标签: python arcgis arcpy

我已经整理了一个tkinter表单和python脚本,用于从ftp站点下载文件。文件名位于shapefile的属性表中,以及文件名对应的整体名称。换句话说,我查找名称如“CABOT”并下载文件名34092_18.tif。但是,如果名称有撇号,例如“O'KEAN”,它会给我带来麻烦。我尝试替换撇号,就像我在之前的脚本中所做的那样,但它没有下载任何东西....

    whereExp = quadField + " = " + "'" + quadName.replace("'", '"') + "'"
    quadFields = ["FILENAME"]

    c = arcpy.da.SearchCursor(collarlessQuad, quadFields, whereExp)
    for row in c:
        tifFile = row[0]
        tifName = quadName.replace("'", '') + '_' + tifFile
        #fullUrl = ftpUrl + tifFile
        local_filename = os.path.join(downloadDir, tifName)
        lf = open(local_filename, "wb")
        ftp.retrbinary('RETR ' + tifFile, lf.write)
        lf.close()

这是一个脚本的一部分示例,通过替换撇号来正常工作....

where_clause = quadField + " = " + "'" + quad.replace("'", '"') + "'"
#out_quad = quad.replace("'", "") + ".shp"  

arcpy.MakeFeatureLayer_management(quadTable, "quadLayer")
select_out_feature_class = arcpy.SelectLayerByAttribute_management("quadLayer", "NEW_SELECTION",  where_clause)

0 个答案:

没有答案