Broken Script Fix

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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))









share|improve this question









New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • What is you tried if field.name == "NAME": in your code.
    – Keagan Allan
    1 hour ago










  • That worked like a charm!!!!!!!!!!!!!!!!!!!
    – dvldgs05
    55 mins ago










  • @dvldgs05 please accept Keagan's answer if it worked for you.
    – Fezter♦
    45 mins ago














up vote
1
down vote

favorite












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))









share|improve this question









New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • What is you tried if field.name == "NAME": in your code.
    – Keagan Allan
    1 hour ago










  • That worked like a charm!!!!!!!!!!!!!!!!!!!
    – dvldgs05
    55 mins ago










  • @dvldgs05 please accept Keagan's answer if it worked for you.
    – Fezter♦
    45 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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))









share|improve this question









New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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))






arcpy python






share|improve this question









New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









Keagan Allan

2,1201416




2,1201416






New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









dvldgs05

61




61




New contributor




dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






dvldgs05 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • What is you tried if field.name == "NAME": in your code.
    – Keagan Allan
    1 hour ago










  • That worked like a charm!!!!!!!!!!!!!!!!!!!
    – dvldgs05
    55 mins ago










  • @dvldgs05 please accept Keagan's answer if it worked for you.
    – Fezter♦
    45 mins ago
















  • What is you tried if field.name == "NAME": in your code.
    – Keagan Allan
    1 hour ago










  • That worked like a charm!!!!!!!!!!!!!!!!!!!
    – dvldgs05
    55 mins ago










  • @dvldgs05 please accept Keagan's answer if it worked for you.
    – Fezter♦
    45 mins ago















What is you tried if field.name == "NAME": in your code.
– Keagan Allan
1 hour ago




What is you tried if field.name == "NAME": in your code.
– Keagan Allan
1 hour ago












That worked like a charm!!!!!!!!!!!!!!!!!!!
– dvldgs05
55 mins ago




That worked like a charm!!!!!!!!!!!!!!!!!!!
– dvldgs05
55 mins ago












@dvldgs05 please accept Keagan's answer if it worked for you.
– Fezter♦
45 mins ago




@dvldgs05 please accept Keagan's answer if it worked for you.
– Fezter♦
45 mins ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













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":





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    dvldgs05 is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f298266%2fbroken-script-fix%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    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":





    share|improve this answer
























      up vote
      2
      down vote













      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":





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        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":





        share|improve this answer












        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":






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Keagan Allan

        2,1201416




        2,1201416




















            dvldgs05 is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            dvldgs05 is a new contributor. Be nice, and check out our Code of Conduct.












            dvldgs05 is a new contributor. Be nice, and check out our Code of Conduct.











            dvldgs05 is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f298266%2fbroken-script-fix%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery