bmillerdot

Field values with trailing BackSlash Kills the Python for gp.CalculateField (v9.3)

Discussion created by bmillerdot on Dec 9, 2011
I think that gp.CalculateField does not work if the field value has a backslash (\) or a quote (')

I need to strip (Trim) and Replace for each field value.

This was easy using VB but now it's difficult in Python. I'm now required to use Python because ESRI told us not to use .NET

outstr = instr.replace('|',' ').strip()\n\

*******************************
I don't think the codeblock is a problem because it does not appear to get that far before the error message:
"fixvalue(str(!Field!))" (errror seems to be on this statement)
"fixvalue(str(\"|\")"  (appears like this in the error message)

expr = "fixvalue(str(!Field!))"
codeblock = "def fixvalue(instr):\n\
      outstr = instr.replace('|',' ').strip()\n\
      return outstr"
gp.CalculateField_management(FeaClass, "Field", expr, "PYTHON", codeblock)

Outcomes