Saturday 21 July 2018

python - Finding the index of a field with its name using arcpy


I want to extract the index of a field with its name using arcpy. It seems what I have written is so dumb. Is there any simpler method with out using for-loop?


    import arcpy

fieldList = arcpy.ListFields(self.address_ref_layer1)
self.field_name = []

for field in fieldList:
self.field_name.append(field.name)
#self.remove_pseudo_nodes()
print self.field_name
print self.field_name.index(u"NAMN1")

It could also be written:


    fieldList = arcpy.ListFields(self.address_ref_layer1
name_index = [f.name for f in fieldList].index(u"NAMN1")


The ListFiled function returns list of field objects with many properties as well as name, but no function to return the index of the field which has a specific name?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...