ERROR

'NoneType' object has no attribute 'replace'

Last Published: October 1, 2025

Error Message

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'
Error message

Cause

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.

Attribute table with Null values

The following code sample shows how the error can be reproduced:
import arcpy

cursor = arcpy.da.UpdateCursor ("[Feature]", "[Field Name]"

for row in cursor:
        row[0] = row[0].replace("%20", " ")
        cursor.updateRow(row)

 

Solution or Workaround

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)
Python script

 

Article ID: 000014467

Software:
  • ArcMap
  • ArcGIS Pro

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options