Monday, 25 January 2016

arcgis desktop - ArcPy Field Calculation with special characters


I'm trying to calculate a string field, using "µSv/h". Running this in the manual field calculator works just fine, but I've tried this in the Python window in ArcMap as well as the IDLE, but both fail. For the line below it says invalid syntax.


arcpy.CalculateField_management(tblTempAssayImportName,"Dose_units",""""µSv/h"""","PYTHON_9.3")

When I try to remove the additional three quotes, it comes up with a 000539 error.


I've tried using r to escape, The line above comes straight from the snippet after running the field calculator manually. Not sure why this isn't working, but I'm assuming it's the special characters.




Answer



Seems like I needed to escape the text with different quotes and then add one set for the text to be sent to the calculator. In this case I used three sets of single quotes and one set of double. This also escaped the special characters.


arcpy.CalculateField_management(tblTempAssayImportName,"Dose_units",'''"µSv/h"'‌​'',"PYTHON_9.3")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...