Writing ArcPy UpdateCursor based on row test?

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











up vote
2
down vote

favorite












I'm working on building a series of updates to street feature class based on fields inside the class. I was attempting to do this with update cursor to get better performance.



When the Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"



The Cursor runs for a little while but then none of the rows are actually updated.
I had tried adding the print statment to see if it was stopping on those rows that matched, but none printed.



So I'm assuming that my row test is failing?



fc = r'C:GISSept2018_MergeLA.gdbNW_GC'
fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if (row[0] is None and row[3] == 2 and row[4] == 1):
row[5] == "Exit Ramp"
# print("Updated"+row[6])
cursor.updateRow(row)
print ("Processing complete")









share|improve this question









New contributor




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















  • 1




    It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
    – PolyGeo♦
    4 hours ago










  • row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
    – Michael Stimson
    4 hours ago











  • For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
    – DanceDad
    4 hours ago







  • 1




    You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
    – Michael Stimson
    4 hours ago






  • 1




    What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
    – Michael Stimson
    2 hours ago














up vote
2
down vote

favorite












I'm working on building a series of updates to street feature class based on fields inside the class. I was attempting to do this with update cursor to get better performance.



When the Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"



The Cursor runs for a little while but then none of the rows are actually updated.
I had tried adding the print statment to see if it was stopping on those rows that matched, but none printed.



So I'm assuming that my row test is failing?



fc = r'C:GISSept2018_MergeLA.gdbNW_GC'
fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if (row[0] is None and row[3] == 2 and row[4] == 1):
row[5] == "Exit Ramp"
# print("Updated"+row[6])
cursor.updateRow(row)
print ("Processing complete")









share|improve this question









New contributor




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















  • 1




    It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
    – PolyGeo♦
    4 hours ago










  • row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
    – Michael Stimson
    4 hours ago











  • For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
    – DanceDad
    4 hours ago







  • 1




    You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
    – Michael Stimson
    4 hours ago






  • 1




    What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
    – Michael Stimson
    2 hours ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm working on building a series of updates to street feature class based on fields inside the class. I was attempting to do this with update cursor to get better performance.



When the Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"



The Cursor runs for a little while but then none of the rows are actually updated.
I had tried adding the print statment to see if it was stopping on those rows that matched, but none printed.



So I'm assuming that my row test is failing?



fc = r'C:GISSept2018_MergeLA.gdbNW_GC'
fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if (row[0] is None and row[3] == 2 and row[4] == 1):
row[5] == "Exit Ramp"
# print("Updated"+row[6])
cursor.updateRow(row)
print ("Processing complete")









share|improve this question









New contributor




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











I'm working on building a series of updates to street feature class based on fields inside the class. I was attempting to do this with update cursor to get better performance.



When the Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"



The Cursor runs for a little while but then none of the rows are actually updated.
I had tried adding the print statment to see if it was stopping on those rows that matched, but none printed.



So I'm assuming that my row test is failing?



fc = r'C:GISSept2018_MergeLA.gdbNW_GC'
fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if (row[0] is None and row[3] == 2 and row[4] == 1):
row[5] == "Exit Ramp"
# print("Updated"+row[6])
cursor.updateRow(row)
print ("Processing complete")






arcpy cursor






share|improve this question









New contributor




DanceDad 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




DanceDad 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 4 hours ago









PolyGeo♦

52.3k1779236




52.3k1779236






New contributor




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









asked 4 hours ago









DanceDad

111




111




New contributor




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





New contributor





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






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







  • 1




    It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
    – PolyGeo♦
    4 hours ago










  • row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
    – Michael Stimson
    4 hours ago











  • For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
    – DanceDad
    4 hours ago







  • 1




    You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
    – Michael Stimson
    4 hours ago






  • 1




    What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
    – Michael Stimson
    2 hours ago












  • 1




    It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
    – PolyGeo♦
    4 hours ago










  • row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
    – Michael Stimson
    4 hours ago











  • For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
    – DanceDad
    4 hours ago







  • 1




    You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
    – Michael Stimson
    4 hours ago






  • 1




    What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
    – Michael Stimson
    2 hours ago







1




1




It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
– PolyGeo♦
4 hours ago




It sounds like you have no rows where row[0] is None and row[3] == 2 and row[4] == 1. Try printing row[0], row[3] and row[4] just before you test to see if you can spot any rows that should meet the criteria. If you have many thousands to check then just add a where clause like OBJECTID < 10 onto your cursor to keep the output manageable.
– PolyGeo♦
4 hours ago












row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
– Michael Stimson
4 hours ago





row[0] is None should be row[0] == None, though depending on how your fields are populated blank may not be None (Null), check also row[0] == 0 or row[0] == '' depending on your field type.
– Michael Stimson
4 hours ago













For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
– DanceDad
4 hours ago





For this test I have 2460 fields out of close to 1 million, that show up when doing arcpy.management.SelectLayerByAttribute("NW_GC", "SUBSET_SELECTION", "Streets_GC_FULLNAME IS NULL And Streets_NW_SLIPRD = 2 And Streets_NW_RAMP = 1", None)
– DanceDad
4 hours ago





1




1




You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
– Michael Stimson
4 hours ago




You could create a selection on your layer or supply the query in the update cursor.. if you're creating a selection you should be able to use int(arcpy.GetCount_management("NW_GC").getOutput(0)) to tell if you've got any features that satisfy the query.
– Michael Stimson
4 hours ago




1




1




What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
– Michael Stimson
2 hours ago




What do you get when you print the updated row? If you're running from the toolbox you may need to use arcpy.AddMessage("Updated ".format(row[6])) to get the message to show up in the tool dialog - also works in CMD and from the python console.
– Michael Stimson
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













There are three problems with your code that I can see:



PROBLEM 1:



The line row[5] == "Exit Ramp" should use = (assign a value) not == (testing for equality). row[5] is not actually being assigned a value by the statement as it is. In fact nothing at all is being done by that statement.



PROBLEM 2:



Your row indexes appear to be a bit muddled. You have 6 fields in your cursor. They are zero-indexed so the last field is row[5], not row[6]. So I would expect that the (commented out) print statement would crash if uncommented (and processing actually reached that point).



Your fields are:



fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']


So...




  • row[0] is 'Streets_GC_FULLNAME'


  • row[1] is 'Streets_NW_FEATTYP'


  • row[2] is 'Streets_NW_SLIPRD'


  • row[3] is 'Streets_NW_RAMP'


  • row[4] is 'StreetName'


  • row[5] is 'Streets_NW_ID'


  • row[6] DOES NOT EXIST and is an out-of-range index

So your if statement translates to something like:



if (Streets_GC_FULLNAME is None and Streets_NW_RAMP == 2 and StreetName == 1)


Do you really have any features with StreetName == 1 ? I would guess that StreetName is a string, so testing for equality with 1 is probably not what you really want.



PROBLEM 3:



Assuming problem 1 gets fixed...



Similarly, row[5] = "Exit Ramp" (single '=') would translate to something like Streets_NW_ID = "Exit Ramp"



From your question, I don't think this is what you intended.



Solution:



You said in your question that you wanted to test for:




Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"




This should be something like (untested):



 if row[0] is None and row[2] == 2 and row[3] == 1
row[4] = "Exit Ramp"
print "Updated ".format(row[5])
cursor.updateRow(row)





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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    DanceDad 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%2f300937%2fwriting-arcpy-updatecursor-based-on-row-test%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













    There are three problems with your code that I can see:



    PROBLEM 1:



    The line row[5] == "Exit Ramp" should use = (assign a value) not == (testing for equality). row[5] is not actually being assigned a value by the statement as it is. In fact nothing at all is being done by that statement.



    PROBLEM 2:



    Your row indexes appear to be a bit muddled. You have 6 fields in your cursor. They are zero-indexed so the last field is row[5], not row[6]. So I would expect that the (commented out) print statement would crash if uncommented (and processing actually reached that point).



    Your fields are:



    fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']


    So...




    • row[0] is 'Streets_GC_FULLNAME'


    • row[1] is 'Streets_NW_FEATTYP'


    • row[2] is 'Streets_NW_SLIPRD'


    • row[3] is 'Streets_NW_RAMP'


    • row[4] is 'StreetName'


    • row[5] is 'Streets_NW_ID'


    • row[6] DOES NOT EXIST and is an out-of-range index

    So your if statement translates to something like:



    if (Streets_GC_FULLNAME is None and Streets_NW_RAMP == 2 and StreetName == 1)


    Do you really have any features with StreetName == 1 ? I would guess that StreetName is a string, so testing for equality with 1 is probably not what you really want.



    PROBLEM 3:



    Assuming problem 1 gets fixed...



    Similarly, row[5] = "Exit Ramp" (single '=') would translate to something like Streets_NW_ID = "Exit Ramp"



    From your question, I don't think this is what you intended.



    Solution:



    You said in your question that you wanted to test for:




    Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"




    This should be something like (untested):



     if row[0] is None and row[2] == 2 and row[3] == 1
    row[4] = "Exit Ramp"
    print "Updated ".format(row[5])
    cursor.updateRow(row)





    share|improve this answer


























      up vote
      2
      down vote













      There are three problems with your code that I can see:



      PROBLEM 1:



      The line row[5] == "Exit Ramp" should use = (assign a value) not == (testing for equality). row[5] is not actually being assigned a value by the statement as it is. In fact nothing at all is being done by that statement.



      PROBLEM 2:



      Your row indexes appear to be a bit muddled. You have 6 fields in your cursor. They are zero-indexed so the last field is row[5], not row[6]. So I would expect that the (commented out) print statement would crash if uncommented (and processing actually reached that point).



      Your fields are:



      fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']


      So...




      • row[0] is 'Streets_GC_FULLNAME'


      • row[1] is 'Streets_NW_FEATTYP'


      • row[2] is 'Streets_NW_SLIPRD'


      • row[3] is 'Streets_NW_RAMP'


      • row[4] is 'StreetName'


      • row[5] is 'Streets_NW_ID'


      • row[6] DOES NOT EXIST and is an out-of-range index

      So your if statement translates to something like:



      if (Streets_GC_FULLNAME is None and Streets_NW_RAMP == 2 and StreetName == 1)


      Do you really have any features with StreetName == 1 ? I would guess that StreetName is a string, so testing for equality with 1 is probably not what you really want.



      PROBLEM 3:



      Assuming problem 1 gets fixed...



      Similarly, row[5] = "Exit Ramp" (single '=') would translate to something like Streets_NW_ID = "Exit Ramp"



      From your question, I don't think this is what you intended.



      Solution:



      You said in your question that you wanted to test for:




      Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"




      This should be something like (untested):



       if row[0] is None and row[2] == 2 and row[3] == 1
      row[4] = "Exit Ramp"
      print "Updated ".format(row[5])
      cursor.updateRow(row)





      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        There are three problems with your code that I can see:



        PROBLEM 1:



        The line row[5] == "Exit Ramp" should use = (assign a value) not == (testing for equality). row[5] is not actually being assigned a value by the statement as it is. In fact nothing at all is being done by that statement.



        PROBLEM 2:



        Your row indexes appear to be a bit muddled. You have 6 fields in your cursor. They are zero-indexed so the last field is row[5], not row[6]. So I would expect that the (commented out) print statement would crash if uncommented (and processing actually reached that point).



        Your fields are:



        fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']


        So...




        • row[0] is 'Streets_GC_FULLNAME'


        • row[1] is 'Streets_NW_FEATTYP'


        • row[2] is 'Streets_NW_SLIPRD'


        • row[3] is 'Streets_NW_RAMP'


        • row[4] is 'StreetName'


        • row[5] is 'Streets_NW_ID'


        • row[6] DOES NOT EXIST and is an out-of-range index

        So your if statement translates to something like:



        if (Streets_GC_FULLNAME is None and Streets_NW_RAMP == 2 and StreetName == 1)


        Do you really have any features with StreetName == 1 ? I would guess that StreetName is a string, so testing for equality with 1 is probably not what you really want.



        PROBLEM 3:



        Assuming problem 1 gets fixed...



        Similarly, row[5] = "Exit Ramp" (single '=') would translate to something like Streets_NW_ID = "Exit Ramp"



        From your question, I don't think this is what you intended.



        Solution:



        You said in your question that you wanted to test for:




        Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"




        This should be something like (untested):



         if row[0] is None and row[2] == 2 and row[3] == 1
        row[4] = "Exit Ramp"
        print "Updated ".format(row[5])
        cursor.updateRow(row)





        share|improve this answer














        There are three problems with your code that I can see:



        PROBLEM 1:



        The line row[5] == "Exit Ramp" should use = (assign a value) not == (testing for equality). row[5] is not actually being assigned a value by the statement as it is. In fact nothing at all is being done by that statement.



        PROBLEM 2:



        Your row indexes appear to be a bit muddled. You have 6 fields in your cursor. They are zero-indexed so the last field is row[5], not row[6]. So I would expect that the (commented out) print statement would crash if uncommented (and processing actually reached that point).



        Your fields are:



        fields = ['Streets_GC_FULLNAME', 'Streets_NW_FEATTYP', 'Streets_NW_SLIPRD', 'Streets_NW_RAMP', 'StreetName','Streets_NW_ID']


        So...




        • row[0] is 'Streets_GC_FULLNAME'


        • row[1] is 'Streets_NW_FEATTYP'


        • row[2] is 'Streets_NW_SLIPRD'


        • row[3] is 'Streets_NW_RAMP'


        • row[4] is 'StreetName'


        • row[5] is 'Streets_NW_ID'


        • row[6] DOES NOT EXIST and is an out-of-range index

        So your if statement translates to something like:



        if (Streets_GC_FULLNAME is None and Streets_NW_RAMP == 2 and StreetName == 1)


        Do you really have any features with StreetName == 1 ? I would guess that StreetName is a string, so testing for equality with 1 is probably not what you really want.



        PROBLEM 3:



        Assuming problem 1 gets fixed...



        Similarly, row[5] = "Exit Ramp" (single '=') would translate to something like Streets_NW_ID = "Exit Ramp"



        From your question, I don't think this is what you intended.



        Solution:



        You said in your question that you wanted to test for:




        Streets_GC_FullName is null, the STREETS_NW_SLIPRD = 2 and STREETS_NW_RAMP=1, then change the Streetname field to "Exit Ramp"




        This should be something like (untested):



         if row[0] is None and row[2] == 2 and row[3] == 1
        row[4] = "Exit Ramp"
        print "Updated ".format(row[5])
        cursor.updateRow(row)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago

























        answered 2 hours ago









        Son of a Beach

        1,265618




        1,265618




















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









             

            draft saved


            draft discarded


















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












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











            DanceDad 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%2f300937%2fwriting-arcpy-updatecursor-based-on-row-test%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