1

This question already has an answer here:

I've got a Polygon Feature Class of communities in switzerland. Unfortunately, the names in the attribute Field "NAME" include spaces, brackets and ä/ ö/ ü characters. For further processing, i need to remove the spaces and brackets and to replace ä --> ae, ö --> oe, ü --> ue. I've tried to do this using update cursor but i don't get it to work:

with arcpy.da.UpdateCursor("AVR_GEM","NAME") as cursor: for row in cursor: row = str(row).replace("ä","ae") row = str(row).replace("ö","oe") row = str(row).replace("ü","oe") row = str(row).replace(" ","") row = str(row).replace("(","") cursor.updateRow(row)

Can anyone show me a quick way to get the job done?

marked as duplicate by John Powell, Brad Nesom, PolyGeo Feb 2 '16 at 21:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Could you tell us where it is failing? What error messages do you see? I presume this is ArcGIS, what version are you using? – jon_two Feb 2 '16 at 10:46
  • 2
    Think of row as a list and name is the second item you want to edit. So you need to choose that and you normally do that by the index. In your case it would be row[1] = str(row[1]).replace..... Your updateRow line stays the same. – Hornbydd Feb 2 '16 at 10:50
1

I suppose you need something like this:

cursor = arcpy.da.UpdateCursor("AVR_GEM","NAME"):
for row in cursor:
    row[0] = str(row[0]).replace("ä","ae").replace("ö","oe").replace("ü","oe").replace(" ","").replace("(","")
    cursor.updateRow(row)

Alternativly you may also directly change the row´s attribute:

row.NAME = ...
  • when i apply this, i get the following message: UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 5: ordinal not in range(128).Obviously the "ü" i'm specifying to be replaced cannot be dealt with... – Flousen Feb 2 '16 at 12:26
  • This doesn't work since you need to use unicode strings instead of the actual ä and ö. See this question: gis.stackexchange.com/questions/58251/… – Martin Feb 2 '16 at 14:39

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