问题描述
我正在使用python 2.7(由于有效的IT控制,我无法升级版本)。我正在尝试匹配要素类中两个不同属性列中的选定数据(数字)以进行处理。
我需要将“到节点”与“从节点”匹配。我尝试了几种不同的方法(全部注释掉了)。我最接近的是使用getattr函数,但是我得到了...
属性错误:'str'对象没有属性'257878459',这是第一条记录中的数据。 列中的数据为数字,但我必须转换为字符串才能使用getattr,因为这表明我需要一个字符串。我也尝试了getvalue失败。
我觉得我缺少一些简单的东西,但是python有一些新的东西。
HIFLD_repair = (r'D:\mypathfordata\HIFLD_final.shp')
hi_fields = ["ToNodeID","FromNodeID"]
def repair_HILFD_heli():
arcpy.MakeFeatureLayer_management(HIFLD_repair,'hi_lyr')#
print('HIFLD Temp layer made')
arcpy.SelectLayerByLocation_management ('hi_lyr',"BOUNDARY_touches",HIFLD_repair,"","NEW_SELECTION","INVERT")# These are the helicopter roads SELECTED
print('Features inverted')
with arcpy.da.SearchCursor('hi_lyr',hi_fields) as cursor:
for row in cursor:
getattr('hi_lyr',str(row[0]))#attribute name must be string
print(row[0])
#'str' object has no attribute '257878459' THIS IS THE FirsT RECORD OF ATTRIUBTE
#UNSUCCESSFUL
#value1 = row.getValue(row[0])#tuple object has no attribute get value
#value1 = '{}'.getValue(row[0])# Trying to conver to tuple. ERR string object has no attribute getValue
#print(value1)
#UNSUCCESSFUL
#if row[0] == row[1]:
#print(row[0] + ' ' + row[1])#This call is not printing / doing nothing
#print(row[0])#This does print the selected data.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)