ERROR
Attempts to use the replace() function in a Python script on a string field fail and return the following error:
Error: 'NoneType' object has no attribute 'replace'

The error occurs when there are Null values in the selected field. The following image shows an attribute table with a field containing Null values.

import arcpy
cursor = arcpy.da.UpdateCursor ("[Feature]", "[Field Name]"
for row in cursor:
row[0] = row[0].replace("%20", " ")
cursor.updateRow(row)
Use the selection clause to avoid executing the replace() function on Null values in the field. The following code sample demonstrates how to do so:
import arcpy
cursor = arcpy.da.UpdateCursor("[Feature]", "[Field Name]")
for row in cursor:
if row[0] == None:
row[0] = row[0]
else:
row[0] = row[0].replace("%20", " ")
cursor.updateRow (row)

Article ID: 000014467
Get help from ArcGIS experts
Start chatting now