0

I have this script which gives me an attribute error and points out line 8.

The error says

" 'list' object has no attribute 'name'"

Not sure what went wrong.

How do I fix this script to run?

import arcpy
from arcpy import env
env.workspace = "C:/EsriPress/Python/Data/MyFolder"
fc = "airports.shp"
rows = arcpy.SearchCursor(fc)
fields = arcpy.ListFields(fc)
for field in fields:
    if fields.name == "NAME":
        for row in rows:
            print "Name = ({0}".format(row.getValue(field.name))
  • What is you tried if field.name == "NAME": in your code. – Keagan Allan Oct 9 '18 at 2:22
  • That worked like a charm!!!!!!!!!!!!!!!!!!! – dvldgs05 Oct 9 '18 at 2:31
  • 1
    @dvldgs05 please accept Keagan's answer if it worked for you. – Fezter Oct 9 '18 at 2:40
5

From the code provided, I tested the following:

Your if Statement is looking at "Fields" You want the if statement to look at the Field in the list of Fields.

Change:

if fields.name == "NAME":

to

if field.name == "NAME":

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.