i have some code that takes a field and finds every unique value in that field. it then creates a layer for each unique value.
The code is working ok , but it is failing when there are \ characters within the value , for example "london\bridge".
If i were to do a manual defination query and save a layer it would work . So why does it not work here ? Anyone have any ideas My code uses the search curosor to get the unique values and iterates through this one at a time saving out a layer .
import arcpy from arcpy import env ## This is where the file that is to be processed is saved arcpy.env.workspace = "S:\\AppsData\\GIS\\PROJECT\\COMPANIES\\SHAPEFILES\\" # The file to be processed Source_File = "SDE_COMPANY_LIST.shp" # The attribute that is being looked at in this case is "COMPANY" , the company bulk list accesses all the values within the given feild in this case it is company Company_Bulk_Company_List = [row for row in arcpy.da.SearchCursor(Source_File,"COMPANY")] #the UniqueCompany variable takes all the values from the field and returns a unique set , which gives the basis for every layer to be write UniqueCompany = set(Company_Bulk_Company_List) print UniqueCompany # Getting the list out for company_query in UniqueCompany: env.workspace = "S:\\AppsData\\GIS\\PROJECT\\COMPANIES\\SHAPEFILES\\" out_layer0 = str(company_query)+"lyr" in_layer = out_layer0 out_layer = in_layer +"lyr" #MakeFeatureLayer variables in_features = "SDE_COMPANY_LIST.shp" # The attribute that is being looked at is repeated here where_clause = '"COMPANY" = ' + "'" + company_query + "'" print where_clause workspace = "S:\\AppsData\\GIS\\PROJECT\\COMPANIES\\SHAPEFILES\\" try: # Execute MakeFeatureLayer arcpy.MakeFeatureLayer_management(in_features, out_layer0, where_clause, workspace) # Execute SaveToLayerFile arcpy.SaveToLayerFile_management(in_layer, out_layer, "ABSOLUTE") except: print arcpy.GetMessages()