Python - How to do a character replace when an ! is involved

953
1
Jump to solution
04-03-2017 02:15 PM
IanPeebles
Occasional Contributor III

I am having an issue replacing an ! as a character from my record.  I want to replace a ! as a [blank].  I tried using this statement, but it does not work:

arcpy.CalculateField_management(CISAddressSDEFL, "NEIGHBOUR", "!NEIGHBOUR!.replace(\"!\", \"\")", "PYTHON", "")

All other special characters work, but not the !.  Any ideas on how to perform a replace?

0 Kudos
1 Solution

Accepted Solutions
IanPeebles
Occasional Contributor III

I figured it out, I basically concerted the ! to an ASCI code and it worked.  Here is my syntax:

# ! Screening
arcpy.SelectLayerByAttribute_management(CISAddressSDEFL, "NEW_SELECTION", "NEIGHBOUR LIKE '%!%'")
explanationPointChar = chr(33)
arcpy.CalculateField_management(CISAddressSDEFL, "NEIGHBOUR", "!NEIGHBOUR!.replace(explanationPointChar, \"\")", "PYTHON", "")

View solution in original post

1 Reply
IanPeebles
Occasional Contributor III

I figured it out, I basically concerted the ! to an ASCI code and it worked.  Here is my syntax:

# ! Screening
arcpy.SelectLayerByAttribute_management(CISAddressSDEFL, "NEW_SELECTION", "NEIGHBOUR LIKE '%!%'")
explanationPointChar = chr(33)
arcpy.CalculateField_management(CISAddressSDEFL, "NEIGHBOUR", "!NEIGHBOUR!.replace(explanationPointChar, \"\")", "PYTHON", "")