【在其他版本上未报错,麻烦管理员删除这个帖子吧】给gdb中每个要素的name字段赋值,值为这个要素的名称

【需求描述】gdb中有2个要素,名称分别为“城市”“村庄”,每个要素都已添加了一个字符字段“name”,想使用Arcpy将每个要素的name字段赋值为这个要素的图层名称。如:“城市”的name字段赋值为“城市”,“村庄”的name字段赋值为“村庄”。

【代码如下(版本Arcgis Pro 2.6)】
import arcpy
arcpy.env.workspace = r"D:\新数据.gdb"
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
    arcpy.CalculateField_management(fc,"name",fc)

【报错】
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
NameError: name '城市' is not defined

ExecuteError Traceback (most recent call last) In [29]: Line 6: arcpy.CalculateField_management(fc,'name',fc) File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateField: Line 5194: raise e File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CalculateField: Line 5191: retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True))) File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>: Line 512: return lambda *args: val(*gp_fixargs(args, True)) 
ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. Failed to execute (CalculateField).
 
想请问各位大神是哪里出了错呢?应如何解决?谢谢!
已邀请:

要回复问题请先登录注册