Select to view content in your preferred language

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

737
0
12-09-2011 06:25 AM
BillMiller
Deactivated User
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)
Tags (2)
0 Kudos
0 Replies