0

I have a number of feature classes in which some records in the attribute tables need updating with new information. However the strings to replace aren't found in the UpdateCursor due to the presence of accented characters. I've run the same search on the table and just removed the accented e (é) from both the record and the search string and the string is found and replaced correctly.

# For each row, evaluate the PRESENCE field (index position 
# of 0), 
# and update with new value if the record reads
# "Présence n'est pas probable"
with arcpy.da.UpdateCursor(fc, inputField) as cursor:
 for row in cursor:
 if row[0] == "Présence n'est pas probable":
 row[0] = "Non probable"
 cursor.updateRow(row)
 else:
 pass

How does one search for a string with accented characters?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 25, 2018 at 15:47
2

1 Answer 1

1

As commented you can remove the accents using unicodedata.normalize. I have not tried the code but I think it should work:

import unicodedata, arcpy
def remove_accents(input_str):
 #From: https://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
 nfkd_form = unicodedata.normalize('NFKD', input_str)
 only_ascii = nfkd_form.encode('ASCII', 'ignore')
 return only_ascii
with arcpy.da.UpdateCursor(fc, inputField) as cursor:
 for row in cursor:
 if remove_accents(row[0]) == remove_accents("Présence n'est pas probable"):
 row[0] = "Non probable"
 cursor.updateRow(row)
 else:
 pass
answered Jul 26, 2018 at 9:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.