ArcPy Update Cursor Not Populating Field? Planned maintenance scheduled April 23, 2019 at...

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

The test team as an enemy of development? And how can this be avoided?

How do you write "wild blueberries flavored"?

Is a copyright notice with a non-existent name be invalid?

Why are current probes so expensive?

Centre cell vertically in tabularx

How could a hydrazine and N2O4 cloud (or it's reactants) show up in weather radar?

First paper to introduce the "principal-agent problem"

How does the body cool itself in a stillsuit?

Are there any irrational/transcendental numbers for which the distribution of decimal digits is not uniform?

What does 丫 mean? 丫是什么意思?

Derived column in a data extension

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

How many time has Arya actually used Needle?

Did pre-Columbian Americans know the spherical shape of the Earth?

Is there a spell that can create a permanent fire?

.bashrc alias for a command with fixed second parameter

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Adapting the Chinese Remainder Theorem (CRT) for integers to polynomials

3D Masyu - A Die

Twin's vs. Twins'

When does a function NOT have an antiderivative?

What was the last profitable war?

Baking rewards as operations



ArcPy Update Cursor Not Populating Field?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Calculating field in which null values may be present?Using Update Cursor?Calculate and Restart Sequential ID for Unique Values in a FieldHow to update new column in attribute table with same values but different field type?Designing Update Cursor that updates rows found between two values?Optimizing Field Update - Update Cursor, ArcPyFinding matching rows across columns and populating a separate columnLooping through data to perform one to many join in ArcPy?Adding field which, depending on direction field value, gets value from previous or next row/feature in another field?Comparing value with value from the next row





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I recognize similar questions have been asked but I have yet to see what my code is lacking in any of their answers.



I am trying to use the code below to periodically update attributes in a Feature Class that is often added to during our survey. The goal is every time the 'SBP Anomaly' or 'BS Anomaly' is present in the 'Target_Typ' column a sequential integer will be marked in the 'SBP_Num' and 'BCKSCTR_Nu'(Better name forthcoming) columns respectively.



The first two 'for loops' under my Update Cursor are operating correctly, however, the third doesn't update/populate its target fields when the conditions are met.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for y in rows:
y[0] = x
x+=1
rows.updateRow(y)

for row in rows:
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
rows.updateRow(row)

for TypeCount in rows:
if row[1] == 'SBP Anomaly':
row[4] = int(s)
s += 1
elif row[1] == 'BS Anomaly':
row[3] = int(i)
i += 1
else:
pass
rows.updateRow(TypeCount)

del rows


An image of the attribute table I am trying to manipulate is included also for reference.
I have made sure the Target fields for third 'for loop' are set up as the correct object type: short integers (at least I think that's appropriate
) and not strings so they should take the integers i/s. I have tried them as strings and Long integers, and even float one time.



enter image description here



Update based on some suggestions from various users. Tried this code and still no luck.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for row in rows:
row[0] = x
x+=1

if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"

if row[1] == 'SBP Anomaly':
row[4] = s
s += 1
elif row[1] == 'BS Anomaly':
row[3] = i
i += 1
else:
pass
rows.updateRow(row)


Also per one users comment, A more detailed description of what I want to acheive. Entries in this feature class are usually manually entered via creating features, i.e. picking them based on data available. When that happens several attributes need to be update manually.



-The Target_Num or Target number needs to be entered in sequential order. That hasn't been a problem so much.



-The 'BS' and 'SBP' anomalies will have be populated in the Target Type column, however, the WS anomalies need to be manually input in that column. These are added from another software program so that particular attribute needs to be populated. The idea with this code is that it takes another column attribute, one that only exists for the WC anomaly, and when there is data present, set the Target type to 'WC Anomaly'. Elsewise, Make it a Backscatter Anomaly. The only prohibitive condition with this is if there if Target Type is already listed as a 'SBP Anomaly', which should be left alone.



-Lastly, if the Target type is equal to SBP or BS anomaly, then it should populate the SBP/BSCKTR_Num column. This is to keep a running tally of how many of each targets there is.










share|improve this question

























  • Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

    – Vince
    yesterday













  • Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

    – ckhartma621
    23 hours ago








  • 1





    What do you mean by "no luck"

    – BERA
    8 hours ago






  • 1





    Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

    – ckhartma621
    8 hours ago




















0















I recognize similar questions have been asked but I have yet to see what my code is lacking in any of their answers.



I am trying to use the code below to periodically update attributes in a Feature Class that is often added to during our survey. The goal is every time the 'SBP Anomaly' or 'BS Anomaly' is present in the 'Target_Typ' column a sequential integer will be marked in the 'SBP_Num' and 'BCKSCTR_Nu'(Better name forthcoming) columns respectively.



The first two 'for loops' under my Update Cursor are operating correctly, however, the third doesn't update/populate its target fields when the conditions are met.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for y in rows:
y[0] = x
x+=1
rows.updateRow(y)

for row in rows:
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
rows.updateRow(row)

for TypeCount in rows:
if row[1] == 'SBP Anomaly':
row[4] = int(s)
s += 1
elif row[1] == 'BS Anomaly':
row[3] = int(i)
i += 1
else:
pass
rows.updateRow(TypeCount)

del rows


An image of the attribute table I am trying to manipulate is included also for reference.
I have made sure the Target fields for third 'for loop' are set up as the correct object type: short integers (at least I think that's appropriate
) and not strings so they should take the integers i/s. I have tried them as strings and Long integers, and even float one time.



enter image description here



Update based on some suggestions from various users. Tried this code and still no luck.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for row in rows:
row[0] = x
x+=1

if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"

if row[1] == 'SBP Anomaly':
row[4] = s
s += 1
elif row[1] == 'BS Anomaly':
row[3] = i
i += 1
else:
pass
rows.updateRow(row)


Also per one users comment, A more detailed description of what I want to acheive. Entries in this feature class are usually manually entered via creating features, i.e. picking them based on data available. When that happens several attributes need to be update manually.



-The Target_Num or Target number needs to be entered in sequential order. That hasn't been a problem so much.



-The 'BS' and 'SBP' anomalies will have be populated in the Target Type column, however, the WS anomalies need to be manually input in that column. These are added from another software program so that particular attribute needs to be populated. The idea with this code is that it takes another column attribute, one that only exists for the WC anomaly, and when there is data present, set the Target type to 'WC Anomaly'. Elsewise, Make it a Backscatter Anomaly. The only prohibitive condition with this is if there if Target Type is already listed as a 'SBP Anomaly', which should be left alone.



-Lastly, if the Target type is equal to SBP or BS anomaly, then it should populate the SBP/BSCKTR_Num column. This is to keep a running tally of how many of each targets there is.










share|improve this question

























  • Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

    – Vince
    yesterday













  • Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

    – ckhartma621
    23 hours ago








  • 1





    What do you mean by "no luck"

    – BERA
    8 hours ago






  • 1





    Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

    – ckhartma621
    8 hours ago
















0












0








0


0






I recognize similar questions have been asked but I have yet to see what my code is lacking in any of their answers.



I am trying to use the code below to periodically update attributes in a Feature Class that is often added to during our survey. The goal is every time the 'SBP Anomaly' or 'BS Anomaly' is present in the 'Target_Typ' column a sequential integer will be marked in the 'SBP_Num' and 'BCKSCTR_Nu'(Better name forthcoming) columns respectively.



The first two 'for loops' under my Update Cursor are operating correctly, however, the third doesn't update/populate its target fields when the conditions are met.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for y in rows:
y[0] = x
x+=1
rows.updateRow(y)

for row in rows:
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
rows.updateRow(row)

for TypeCount in rows:
if row[1] == 'SBP Anomaly':
row[4] = int(s)
s += 1
elif row[1] == 'BS Anomaly':
row[3] = int(i)
i += 1
else:
pass
rows.updateRow(TypeCount)

del rows


An image of the attribute table I am trying to manipulate is included also for reference.
I have made sure the Target fields for third 'for loop' are set up as the correct object type: short integers (at least I think that's appropriate
) and not strings so they should take the integers i/s. I have tried them as strings and Long integers, and even float one time.



enter image description here



Update based on some suggestions from various users. Tried this code and still no luck.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for row in rows:
row[0] = x
x+=1

if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"

if row[1] == 'SBP Anomaly':
row[4] = s
s += 1
elif row[1] == 'BS Anomaly':
row[3] = i
i += 1
else:
pass
rows.updateRow(row)


Also per one users comment, A more detailed description of what I want to acheive. Entries in this feature class are usually manually entered via creating features, i.e. picking them based on data available. When that happens several attributes need to be update manually.



-The Target_Num or Target number needs to be entered in sequential order. That hasn't been a problem so much.



-The 'BS' and 'SBP' anomalies will have be populated in the Target Type column, however, the WS anomalies need to be manually input in that column. These are added from another software program so that particular attribute needs to be populated. The idea with this code is that it takes another column attribute, one that only exists for the WC anomaly, and when there is data present, set the Target type to 'WC Anomaly'. Elsewise, Make it a Backscatter Anomaly. The only prohibitive condition with this is if there if Target Type is already listed as a 'SBP Anomaly', which should be left alone.



-Lastly, if the Target type is equal to SBP or BS anomaly, then it should populate the SBP/BSCKTR_Num column. This is to keep a running tally of how many of each targets there is.










share|improve this question
















I recognize similar questions have been asked but I have yet to see what my code is lacking in any of their answers.



I am trying to use the code below to periodically update attributes in a Feature Class that is often added to during our survey. The goal is every time the 'SBP Anomaly' or 'BS Anomaly' is present in the 'Target_Typ' column a sequential integer will be marked in the 'SBP_Num' and 'BCKSCTR_Nu'(Better name forthcoming) columns respectively.



The first two 'for loops' under my Update Cursor are operating correctly, however, the third doesn't update/populate its target fields when the conditions are met.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for y in rows:
y[0] = x
x+=1
rows.updateRow(y)

for row in rows:
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
rows.updateRow(row)

for TypeCount in rows:
if row[1] == 'SBP Anomaly':
row[4] = int(s)
s += 1
elif row[1] == 'BS Anomaly':
row[3] = int(i)
i += 1
else:
pass
rows.updateRow(TypeCount)

del rows


An image of the attribute table I am trying to manipulate is included also for reference.
I have made sure the Target fields for third 'for loop' are set up as the correct object type: short integers (at least I think that's appropriate
) and not strings so they should take the integers i/s. I have tried them as strings and Long integers, and even float one time.



enter image description here



Update based on some suggestions from various users. Tried this code and still no luck.



import arcpy

fc = arcpy.GetParameterAsText(0)

fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]

i = 1
x = 1
s = 1

with arcpy.da.UpdateCursor(fc,fields) as rows:
for row in rows:
row[0] = x
x+=1

if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"

if row[1] == 'SBP Anomaly':
row[4] = s
s += 1
elif row[1] == 'BS Anomaly':
row[3] = i
i += 1
else:
pass
rows.updateRow(row)


Also per one users comment, A more detailed description of what I want to acheive. Entries in this feature class are usually manually entered via creating features, i.e. picking them based on data available. When that happens several attributes need to be update manually.



-The Target_Num or Target number needs to be entered in sequential order. That hasn't been a problem so much.



-The 'BS' and 'SBP' anomalies will have be populated in the Target Type column, however, the WS anomalies need to be manually input in that column. These are added from another software program so that particular attribute needs to be populated. The idea with this code is that it takes another column attribute, one that only exists for the WC anomaly, and when there is data present, set the Target type to 'WC Anomaly'. Elsewise, Make it a Backscatter Anomaly. The only prohibitive condition with this is if there if Target Type is already listed as a 'SBP Anomaly', which should be left alone.



-Lastly, if the Target type is equal to SBP or BS anomaly, then it should populate the SBP/BSCKTR_Num column. This is to keep a running tally of how many of each targets there is.







arcpy cursor arcgis-10.6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 19 mins ago









PolyGeo

54.1k1782246




54.1k1782246










asked yesterday









ckhartma621ckhartma621

12




12













  • Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

    – Vince
    yesterday













  • Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

    – ckhartma621
    23 hours ago








  • 1





    What do you mean by "no luck"

    – BERA
    8 hours ago






  • 1





    Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

    – ckhartma621
    8 hours ago





















  • Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

    – Vince
    yesterday













  • Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

    – ckhartma621
    23 hours ago








  • 1





    What do you mean by "no luck"

    – BERA
    8 hours ago






  • 1





    Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

    – ckhartma621
    8 hours ago



















Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

– Vince
yesterday







Your third code blocks continues to use row, even though it was last defined in the second block, and the TypeCount variable was never modified.

– Vince
yesterday















Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

– ckhartma621
23 hours ago







Jesus... that's embarrassing. Thanks Vince. Unfortunately fixing that didn't quite help. I'll upload the update code.

– ckhartma621
23 hours ago






1




1





What do you mean by "no luck"

– BERA
8 hours ago





What do you mean by "no luck"

– BERA
8 hours ago




1




1





Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

– ckhartma621
8 hours ago







Bera, Im not sure where your answer went, but that put me on the right track. I had been testing this code on an exported geodatabase feature class that had been exported to a shapefile for testing. When I made a test geodatabase and exported it to a FC instead of a SHP, its all of a sudden working a lot better. I'm not sure why that would be, any insight would be great. There are still some bugs but I am definitely on the right track. thanks for your help.

– ckhartma621
8 hours ago












1 Answer
1






active

oldest

votes


















1














Not sure what you are trying to do, your table filled in with your expected values would help.



But your first for loop will exhaust your cursor. Example:



import arcpy

fc = r"X:Testdatapolys.shp"
field = "id"

with arcpy.da.UpdateCursor(fc,field) as cursor:
for row in cursor:
print(f'First loop at {field} {row[0]}')
print('Im empty')

for row2 in cursor:
print(f'Second loop at {field} {row2[0]}')


When first for loop is done the cursor is empty and will not enter second loop:



First loop at id 4
First loop at id 5
First loop at id 2
First loop at id 3
First loop at id 1
Im empty


You have to reset it using cursor.reset() or recreate it to loop over all rows a second time. I have never had to do this since one updatecursor can be used to update multiple fields in a 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',
    autoActivateHeartbeat: false,
    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f319433%2farcpy-update-cursor-not-populating-field%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Not sure what you are trying to do, your table filled in with your expected values would help.



    But your first for loop will exhaust your cursor. Example:



    import arcpy

    fc = r"X:Testdatapolys.shp"
    field = "id"

    with arcpy.da.UpdateCursor(fc,field) as cursor:
    for row in cursor:
    print(f'First loop at {field} {row[0]}')
    print('Im empty')

    for row2 in cursor:
    print(f'Second loop at {field} {row2[0]}')


    When first for loop is done the cursor is empty and will not enter second loop:



    First loop at id 4
    First loop at id 5
    First loop at id 2
    First loop at id 3
    First loop at id 1
    Im empty


    You have to reset it using cursor.reset() or recreate it to loop over all rows a second time. I have never had to do this since one updatecursor can be used to update multiple fields in a row.






    share|improve this answer






























      1














      Not sure what you are trying to do, your table filled in with your expected values would help.



      But your first for loop will exhaust your cursor. Example:



      import arcpy

      fc = r"X:Testdatapolys.shp"
      field = "id"

      with arcpy.da.UpdateCursor(fc,field) as cursor:
      for row in cursor:
      print(f'First loop at {field} {row[0]}')
      print('Im empty')

      for row2 in cursor:
      print(f'Second loop at {field} {row2[0]}')


      When first for loop is done the cursor is empty and will not enter second loop:



      First loop at id 4
      First loop at id 5
      First loop at id 2
      First loop at id 3
      First loop at id 1
      Im empty


      You have to reset it using cursor.reset() or recreate it to loop over all rows a second time. I have never had to do this since one updatecursor can be used to update multiple fields in a row.






      share|improve this answer




























        1












        1








        1







        Not sure what you are trying to do, your table filled in with your expected values would help.



        But your first for loop will exhaust your cursor. Example:



        import arcpy

        fc = r"X:Testdatapolys.shp"
        field = "id"

        with arcpy.da.UpdateCursor(fc,field) as cursor:
        for row in cursor:
        print(f'First loop at {field} {row[0]}')
        print('Im empty')

        for row2 in cursor:
        print(f'Second loop at {field} {row2[0]}')


        When first for loop is done the cursor is empty and will not enter second loop:



        First loop at id 4
        First loop at id 5
        First loop at id 2
        First loop at id 3
        First loop at id 1
        Im empty


        You have to reset it using cursor.reset() or recreate it to loop over all rows a second time. I have never had to do this since one updatecursor can be used to update multiple fields in a row.






        share|improve this answer















        Not sure what you are trying to do, your table filled in with your expected values would help.



        But your first for loop will exhaust your cursor. Example:



        import arcpy

        fc = r"X:Testdatapolys.shp"
        field = "id"

        with arcpy.da.UpdateCursor(fc,field) as cursor:
        for row in cursor:
        print(f'First loop at {field} {row[0]}')
        print('Im empty')

        for row2 in cursor:
        print(f'Second loop at {field} {row2[0]}')


        When first for loop is done the cursor is empty and will not enter second loop:



        First loop at id 4
        First loop at id 5
        First loop at id 2
        First loop at id 3
        First loop at id 1
        Im empty


        You have to reset it using cursor.reset() or recreate it to loop over all rows a second time. I have never had to do this since one updatecursor can be used to update multiple fields in a row.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 16 hours ago

























        answered 17 hours ago









        BERABERA

        17.4k62044




        17.4k62044






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f319433%2farcpy-update-cursor-not-populating-field%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

            Meter-Bus Содержание Параметры шины | Стандартизация |...