Error 000989: Python Syntax Error in Copied Python Snippet

6300
2
Jump to solution
08-25-2014 07:58 AM
ChristopherBlinn1
Occasional Contributor III

I am having an issue with a simple python snippet.

Here's the background: I wanted to include an additional step in a nightly update script that replaces characters in a field that simply do not play nice with a web application that allows users to query the data.  These characters included angle brackets ("<" and ">") which I was trying to replace with "Less Than" and "Greater Than".

So when I was testing the Field Calculation, I finally got it to work the way I wanted to, and as I have done with so many other snippets, I simply copied the Python Snippet of the geoprocess, and pasted into my script.

Below is the snippet:

arcpy.CalculateField_management("path/to/my/layer","field","RemoveBad( !field!)","PYTHON_9.3","def RemoveBad(x):/n   x = x.replace('<=', ' Less Than or Equal To ')/n   x = x.replace('>=', ' Greater Than or Equal To ')/n   x = x.replace('<', ' Less Than ')/n   x = x.replace('>', ' Greater Than ')/n   x = x.replace('=', ' Equal To ')/n   x = x.strip()/n   return x")

Now in my script, I do have a log that reports geoprocessing errors, so when I run the script, I am getting the following:

Executing: CalculateField path\to\my\layer field RemoveBad( !field!) PYTHON_9.3 "def RemoveBad(x):/n   x = x.replace('<=', ' Less Than or Equal To ' )/n   x = x.replace('>=', ' Greater Than or Equal To ')/n   x = x.replace('<', ' Less Than ')/n   x = x.replace('>', ' Greater Than ')/n   x = x.replace('=', ' Equal To ')/n   x = x.strip()/n   return x"

Start Time: Mon Aug 25 09:35:32 2014

Failed to execute. Parameters are not valid.

ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1)

Failed to execute (CalculateField).

Failed at Mon Aug 25 09:35:32 2014 (Elapsed Time: 0.00 seconds)

So I started combing through the script but I cannot find the issue, which leads me to believe it has something to do with the angle brackets.

Any assistance in pointing out where the syntax error is occurring would be appreciated.

Thanks,

Chris B.

0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Occasional Contributor III

It should be \n in the code snippet, not /n.

View solution in original post

0 Kudos
2 Replies
JasonScheirer
Occasional Contributor III

It should be \n in the code snippet, not /n.

0 Kudos
ChristopherBlinn1
Occasional Contributor III

Indeed, I also received a few suggestions here:  arcgis desktop - Python Syntax Error when running Python Snippet of successful geoprocess - Geograph...

Thanks for your feedback!

0 Kudos