I would like to save a new layer file with different definition query, but receive TypeError: 'unicode' object is not callable.

import arcpy

lyrFile = arcpy.mapping.Layer("\path to  layer file\ layerFile.lyr")
field = 'Date_1'
values = "'1950'"
query=str(field) + "=" + str(values)
for lyr in arcpy.mapping.ListLayers(lyrFile, "Name of Layer"):
    lyr.saveACopy("new layerfile.lyr")

Error I receive is:

TypeError: 'unicode' object is not callable

How can I adjust the code so could save layer files with different definition queries?

1 Answer 1


definitionQuery is not a method. It is a property of the Layer class. Since it returns a string, you encounter that error.

It can be used like this:

lyr.definitionQuery = query
  • Thank you, Kubra. The code worked without errors. But still doesn't apply definition query. Basically it saves original layer file. Mar 29, 2020 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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