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.


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.

  • Are µSv and h names of other fields? – Erica May 23 '13 at 0:18
  • 2
    I would say it's because Python is converting µSv to \xe6Sv/h – Nathan W May 23 '13 at 0:21
  • 1
    @Erica the field name I want to calculate is 'Dose_units'. The value I'm calculating is pure text. It just represents the units we measure radiation in. – MierMoto May 26 '13 at 6:46

I'm no expert with character encoding, but I believe Python's interpreter converts your input source to ASCII which is why using triple quotes and the r string prefix aren't having any effect.

What you need to do is use Python's Unicode escape characters and the hexadecimal code for mu, as described in the Unicode HOWTO page. According to the Unicode table, the hexadecimal code for lowercase mu is 03BC. To create a Unicode string in Python for lowercase mu, you would enter u'\u03BC'. Your full field calculator expression would be:

  • I think I would just rename the column :P – Nathan W May 23 '13 at 3:45
  • @NathanW I think the OP wants the field values (not the column name) to have the lowercase mu. – dmahr May 23 '13 at 12:08
  • @dmahr Cheers for the response. I'll have to check this tomorrow to see if this works for me, but it sounds like it might be the issue. I'll let you know. – MierMoto May 26 '13 at 6:48
  • Nope, still getting ERROR 0000593. Something bizarre's going on though. I'm not able to send any text to this field now. I'm simply trying "Test" or even like the snippet's suggesting, """"Test"""". On the former I get the ERROR 000593, but on the latter I simply get an invalid syntax error. – MierMoto May 27 '13 at 1:43
  • Right, got the answer. After getting completely frustrated with this, I started fooling around with different combination of quotes. Looks like a combination of single and double quotes works. In this case, three single quotes escape the double quote, which is then sent to the calculator, with those double quotes in tack. I just print commands using the different combinations and found the one that retains the double quotes. They also escape all the special characters. Works fine now. arcpy.CalculateField_management(tblTempAssayImportName,"Dose_units",'''"µSv/h"''',"PYTHON_9.3") – MierMoto May 27 '13 at 2:03

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.