1

I am using Python scripts to edit the table of many shape files. The following script runs fine, but if there are any " marks in the SIT_FULL_S field, the script errors and shuts down.

gp.CalculateField_management(fc + "\\Parcels.shp","SIT_FULL_S", "!SIT_FULL_S!.lstrip('0')", "PYTHON")
arcgisscripting.ExecuteError: ERROR 000539: Error running expression: "9030 W SR 2 HWY "A"".lstrip('0') <type 'exceptions.SyntaxError'>: invalid syntax (<string>, line 1)
Failed to execute (CalculateField).

I have two options, create a new script that runs through and deletes all occurances of ", and then run the above script or modify the above script to ignore the " and contiue running.

Can anyone help ?

andrew k
  • 11
  • 3

1 Answers1

3

Escape it:

"string \"inner string\""

or don't mix quotations:

'string "inner string"'
Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • 3
    Or triple-quote it: `"""'string', "other string", etc."""` – Seth Jan 13 '11 at 00:55
  • I tried the suggestion below to escape it, but got the following error: gp.CalculateField_management(fc + "\\Parcels.shp","SIT_FULL_S", "!SIT_FULL_S !.lstrip('0\""\"')", "PYTHON") ^ SyntaxError: unexpected character after line continuation character – – andrew k Jan 13 '11 at 23:21
  • I found this, but am having issues using it. – andrew k Jan 19 '11 at 00:42