I am coping with a shapefile and I want to select some rows if the values in one column are in a Python list. The following gives the code I write:
tpu_involved = list(set(dataframe['SmallTPU']))
selection_expression = '"SmallTPU" IN ({0})'.format(', '.join(map(str, tpu_involved)) or 'NULL')
print('---------------------------------------------------------------')
print('The invalid expression is: {}'.format(selection_expression))
print('---------------------------------------------------------------')
selected_layer = arcpy.SelectLayerByAttribute_management(in_layer_or_view='tpu_lyr',
selection_type='NEW_SELECTION',
where_clause=selection_expression)
The tpu_lyr is the layer which is loaded from a local shapefile. I have checked some previous questions like Selecting features by attribute if in Python list?, but it still does not work.
'"SmallTPU" IN ({0}) OR "SmallTPU" IS NULL'.format(...– BERA Jul 27 '19 at 14:52You need to encode the string first...
– Bright Chang Jul 28 '19 at 12:16