For loop within for loop with ArcPy cursor?











up vote
1
down vote

favorite












Below mentioned one is a part of my script.This is working when I assinged numbers for f.(Instead of "f" I have substitute 2.Then it is working).But i want to run this based on the no of rows of the table named "TL"(f).Can any one suggest a method to do this?



f=arcpy.GetCount_management(TL)
with arcpy.da.UpdateCursor(PCL_Info, ['PCL_PG_ID','PCL_IF_LN','PCL_IF_CN','PCL_IF_RM','PCL_IF_LU','PCL_IF_EL','globalid','created_user','created_date','last_edited_user','last_edited_date','adm_gn_ix']) as cursor:
for row in cursor:
for x in range(0,f):
if(row[0] == parcel_ID[x]):
c.append(row[0])
c.append(row[1])
c.append(row[2])









share|improve this question




















  • 1




    BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
    – radouxju
    2 days ago










  • Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
    – BERA
    2 days ago

















up vote
1
down vote

favorite












Below mentioned one is a part of my script.This is working when I assinged numbers for f.(Instead of "f" I have substitute 2.Then it is working).But i want to run this based on the no of rows of the table named "TL"(f).Can any one suggest a method to do this?



f=arcpy.GetCount_management(TL)
with arcpy.da.UpdateCursor(PCL_Info, ['PCL_PG_ID','PCL_IF_LN','PCL_IF_CN','PCL_IF_RM','PCL_IF_LU','PCL_IF_EL','globalid','created_user','created_date','last_edited_user','last_edited_date','adm_gn_ix']) as cursor:
for row in cursor:
for x in range(0,f):
if(row[0] == parcel_ID[x]):
c.append(row[0])
c.append(row[1])
c.append(row[2])









share|improve this question




















  • 1




    BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
    – radouxju
    2 days ago










  • Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
    – BERA
    2 days ago















up vote
1
down vote

favorite









up vote
1
down vote

favorite











Below mentioned one is a part of my script.This is working when I assinged numbers for f.(Instead of "f" I have substitute 2.Then it is working).But i want to run this based on the no of rows of the table named "TL"(f).Can any one suggest a method to do this?



f=arcpy.GetCount_management(TL)
with arcpy.da.UpdateCursor(PCL_Info, ['PCL_PG_ID','PCL_IF_LN','PCL_IF_CN','PCL_IF_RM','PCL_IF_LU','PCL_IF_EL','globalid','created_user','created_date','last_edited_user','last_edited_date','adm_gn_ix']) as cursor:
for row in cursor:
for x in range(0,f):
if(row[0] == parcel_ID[x]):
c.append(row[0])
c.append(row[1])
c.append(row[2])









share|improve this question















Below mentioned one is a part of my script.This is working when I assinged numbers for f.(Instead of "f" I have substitute 2.Then it is working).But i want to run this based on the no of rows of the table named "TL"(f).Can any one suggest a method to do this?



f=arcpy.GetCount_management(TL)
with arcpy.da.UpdateCursor(PCL_Info, ['PCL_PG_ID','PCL_IF_LN','PCL_IF_CN','PCL_IF_RM','PCL_IF_LU','PCL_IF_EL','globalid','created_user','created_date','last_edited_user','last_edited_date','adm_gn_ix']) as cursor:
for row in cursor:
for x in range(0,f):
if(row[0] == parcel_ID[x]):
c.append(row[0])
c.append(row[1])
c.append(row[2])






arcpy cursor for-loop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









PolyGeo

52.8k1779237




52.8k1779237










asked 2 days ago









Shanaka Herath

707




707








  • 1




    BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
    – radouxju
    2 days ago










  • Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
    – BERA
    2 days ago
















  • 1




    BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
    – radouxju
    2 days ago










  • Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
    – BERA
    2 days ago










1




1




BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
– radouxju
2 days ago




BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
– radouxju
2 days ago












Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
– BERA
2 days ago






Hard to tell since we dont know what parcel_ID or c is, or the size of TL. parcel_ID could be a dictionary
– BERA
2 days ago












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Change:



f=arcpy.GetCount_management(TL)


To:



f=int(arcpy.GetCount_management(TL).getOutput(0))


Without getOutput, f is a Result object, not the actual count.



Example:



import arcpy
fc = r"C:TestBuildings.shp"
arcpy.GetCount_management(fc)
<Result '9'>
arcpy.GetCount_management(fc).getOutput(0)
'9'
int(arcpy.GetCount_management(fc).getOutput(0))
9





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


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304052%2ffor-loop-within-for-loop-with-arcpy-cursor%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








    up vote
    3
    down vote



    accepted










    Change:



    f=arcpy.GetCount_management(TL)


    To:



    f=int(arcpy.GetCount_management(TL).getOutput(0))


    Without getOutput, f is a Result object, not the actual count.



    Example:



    import arcpy
    fc = r"C:TestBuildings.shp"
    arcpy.GetCount_management(fc)
    <Result '9'>
    arcpy.GetCount_management(fc).getOutput(0)
    '9'
    int(arcpy.GetCount_management(fc).getOutput(0))
    9





    share|improve this answer



























      up vote
      3
      down vote



      accepted










      Change:



      f=arcpy.GetCount_management(TL)


      To:



      f=int(arcpy.GetCount_management(TL).getOutput(0))


      Without getOutput, f is a Result object, not the actual count.



      Example:



      import arcpy
      fc = r"C:TestBuildings.shp"
      arcpy.GetCount_management(fc)
      <Result '9'>
      arcpy.GetCount_management(fc).getOutput(0)
      '9'
      int(arcpy.GetCount_management(fc).getOutput(0))
      9





      share|improve this answer

























        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        Change:



        f=arcpy.GetCount_management(TL)


        To:



        f=int(arcpy.GetCount_management(TL).getOutput(0))


        Without getOutput, f is a Result object, not the actual count.



        Example:



        import arcpy
        fc = r"C:TestBuildings.shp"
        arcpy.GetCount_management(fc)
        <Result '9'>
        arcpy.GetCount_management(fc).getOutput(0)
        '9'
        int(arcpy.GetCount_management(fc).getOutput(0))
        9





        share|improve this answer














        Change:



        f=arcpy.GetCount_management(TL)


        To:



        f=int(arcpy.GetCount_management(TL).getOutput(0))


        Without getOutput, f is a Result object, not the actual count.



        Example:



        import arcpy
        fc = r"C:TestBuildings.shp"
        arcpy.GetCount_management(fc)
        <Result '9'>
        arcpy.GetCount_management(fc).getOutput(0)
        '9'
        int(arcpy.GetCount_management(fc).getOutput(0))
        9






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        BERA

        13.7k51739




        13.7k51739






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f304052%2ffor-loop-within-for-loop-with-arcpy-cursor%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy