AnsweredAssumed Answered

Selecting records from feature class that have special characters using a dictionary (python)

Question asked by LuisRaulResh on Jul 26, 2019
Latest reply on Jul 26, 2019 by rvburton

I am having trouble selecting counties that have single quotes and/or periods in their name with python that are stored in a dictionary. The below code I have works on county records with no special characters but does not with the special character counties. Any advice/suggestions? 

 

import arcpy
fc = "Maryland_County_Boundaries"
CountyDict = {
"Allegany": "Allegany",
"Anne Arundel": "Anne Arundel",
"Baltimore": "Baltimore",
"Calvert": "Calvert",
"Caroline": "Caroline",
"Carroll": "Carroll",
"Cecil": "Cecil",
"Charles": "Charles",
"Dorchester": "Dorchester",
"Frederick": "Frederick",
"Garrett": "Garrett",
"Harford": "Harford",
"Howard": "Howard",
"Kent": "Kent",
"Montgomery": "Montgomery",
"Prince George\'s": "Prince George\"s",
"Queen Anne\'s": "Queen Anne\"s",
"St. Mary\'s": "St. Mary\"s",
"Somerset": "Somerset",
"Talbot": "Talbot",
"Washington": "Washington",
"Wicomico": "Wicomico",
"Worcester": "Worcester"
}
for k,v in CountyDict.items():
        if k == "Prince George's":
              qry = '"' + "COUNTY" + '"' + " IN ('{}')".format(v)
              arcpy.SelectLayerByAttribute_management(fc, 'NEW_SELECTION',qry)

 

Below is attachment of attribute field with county names.

Attachments

Outcomes