Python - 去掉双引号“使脚本运行

1 投票
1 回答
1663 浏览
提问于 2025-04-16 09:52

我正在用Python脚本来编辑很多形状文件中的表格。下面这个脚本运行得很好,但如果在SIT_FULL_S字段中有任何“符号,脚本就会出错并停止运行。

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).

我有两个选择:要么写一个新脚本,先把所有的“符号删掉,然后再运行上面的脚本;要么修改上面的脚本,让它忽略这些“符号,继续运行下去。

有没有人能帮帮我?

1 个回答

3

把它转义一下:

"string \"inner string\""

或者不要混用引号:

'string "inner string"'

撰写回答