3

I'm trying to apply the following code to extract features that contain these letters 'MW' within the field called 'CODE' for multiple layers. But I'm getting a SyntaxError for line 5 (defintion query).

import arcpy  
mxd = arcpy.mapping.MapDocument("Current")  
layers = arcpy.mapping.ListLayers(mxd)  
for layer in layers:  
    if layer.supports(definitionQuery)  
         layer.definitionQuery = ""CODE" LIKE "('%MW%')"
  • Could you please edit your question to include the formatted syntax error? – Aaron Jun 11 at 2:19
  • Are you trying to extract the features, or update the map? – smiller Jun 11 at 2:37
  • Try removing the parentheses. e.g. """CODE LIKE '%MW%'""". You may also have to add quotes around CODE depending on the field and data type. I'm not sure if arcpy.AddFieldDelimiters works on layers. – smiller Jun 11 at 2:42
5

You need a colon after your line:

if layer.supports(definitionQuery)

should be:

if layer.supports(definitionQuery):

You should also consider modifying your query as was commented by @smiller. It will make your code easier to read.

  • Thanks, both the colon and the parentheses of my definition query solved the problem! – ArVP Jun 11 at 3:20
  • If this answer helped you, please accept the answer so others know you found it useful. – Fezter Jun 11 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.