The Calculate Field tool results in a NameError exception when using Python variables.
上次发布: October 28, 2015ArcGIS for Desktop
漏洞 ID 编号
BUG-000091442
已提交
October 15, 2015
上次修改时间
June 5, 2024
适用范围
ArcGIS for Desktop
找到的版本
10.2.2
操作系统
Windows OS
操作系统版本
7.0 64 Bit
状态
Known Limit
经开发团队审核,已确定此问题与不受 Esri 控制的软件的已知限制有关。 问题的“其他信息”部分可能包含进一步说明。
附加信息
Changes were made around 10.2.2 to properly isolate script tool code, validation and tool like Calculate Field and Calculate Value that use Python internally. Prior to this change, there was potential for confusing and unexpected issues that would be hard to isolate because a variable could be changed in one tool that would impact another tool.
The best strategy for passing variables into CalculateField is using string formatting as shown in the workaround.
解决办法
Use the following code:arcpy.CalculateField_management(table,"gayu", "({0} + 1) / 2".format(funcg), "PYTHON", "")