What is wrong with this code?
query='"depth">1700 AND "depth"<1750'
with arcpy.da.UpdateCursor(out_layer,"depth",query)as cursor:
for row in cursor:
row[0]=0
cursor.updateRow(row)
My query is not updated with the new value.
What is wrong with this code?
query='"depth">1700 AND "depth"<1750'
with arcpy.da.UpdateCursor(out_layer,"depth",query)as cursor:
for row in cursor:
row[0]=0
cursor.updateRow(row)
My query is not updated with the new value.
I'd suggest using the AddFieldDelimiters function. This allows you to enter a field name and a data source, and the field delimiters are automatically added.
field = arcpy.AddFieldDelimiters(out_layer, "depth")
query = """{0} > 1700 AND {0} < 1750""".format(field)
with arcpy.da.UpdateCursor(out_layer, "depth", query) as cursor:
for row in cursor:
row[0] = 0
cursor.updateRow(row)
This is assuming out_layer
is a valid layer.
You don't need double quotes around the field names. If you depth field is numeric, use this:
query = '''depth > 1700 AND depth < 1750'''
Also, enclosing the query with triple quotes is a good way to make sure the quotes delimiting the query won't be matched with the quotes delimiting field values within the query.