I am trying to create a script that automates the generation of a MXD. It does this by the user copying and pasting several variables, running a definition query and exporting an MXD. I can get the script to work with hard coded values as in the code below:
#vari 1
A = "'A', 'B', 'C', 'D'"
#vari 2
B = "'1', '2', '3', '4'"
#Query 1
Query1 = "Field1 = '17' AND NAME in ("+A+")"
#Query 2
Query2 = "Field1 = '1' AND UNIQUE_ID in ("+B+")"
#get list of layers in the mxd
layers = arcpy.mapping.ListLayers(mxd1)
#for the specified list of layers in the mxd, update the definition queries with the current variables
for layer in layers:
if layer.name == "layer1":
layer.definitionQuery = Query1
if layer.name == "layer2":
layer.definitionQuery = Query2
#save a copy of the template mxd do the work request folder
mxd1.saveACopy(workFolder + "\\H_" + jobNumber + "_01.mxd")
#clear the lock on the mxd
del mxd1
The problem I have is that the user enters the data as A, B, C, D (copy and pastes from a report) and I need to transform that for the definition query into "'A', 'B', 'C'" (adding the apostrophes). I can do this for one value (A = "'" + A + "'") but struggling to work out how to format with multiple values. I have tried:
#add apostrophes to list
string1 = "'"
AA = [string1 + x + string1 for x in A]
BB = [string1 + x + string1 for x in B]
but that didn't work. Put simply I would like to add extra characters to the elements in the list (A, B, C, D.... into "'A', 'B', 'C',...") I would welcome any pointers on how I can resolve this?