Select to view content in your preferred language

Nested python loop

1858
2
07-05-2010 06:52 PM
HaydenLewis
Emerging Contributor
I have an issue with a nested python while loop.
The second loop at line 153 updates the "AVPCC" field with the correct value but does not continue on updating the "AVPCC_DES" field as it sould. What have I done wrong here? Please find txt version of py file attached.
0 Kudos
2 Replies
HaydenLewis
Emerging Contributor
I have found a work around for this issue of nested looping, simply by taking the UpdateCursor "while" loop out of the 1st "while" loop. I have instead created a loop of the feature classes and calculated on those on those once the first "while" loop had finished.
Here is the loop I run after the 1st loop in place of it being inside the 1st loop as shown in the attachment.

gp.Workspace = "F:\PROJECTS\VLUIS\PROCESSING\OUTPUT\PILOT\TEMP"
fcList = gp.ListFeatureClasses ("*","all")

fc= fcList.Next()
print fc
while fc <> None:
        curs = gp.UpdateCursor (fc)
        rows = curs.next()
        tenure = rows.GetValue("TENURE")
        public = rows.GetValue("lu_code")
        publicdesc = rows.GetValue("lu_desc")
        oldavpcc = rows.GetValue("AVPCC")
        oldavpccdesc = rows.GetValue("AVPCC_Desc")
        print "starting if on" +fc
        while rows:
         
            if rows.GetValue("TENURE")=="PUBLIC":
                 rows.AVPCC_CODE = rows.GetValue("lu_code")
                 curs.UpdateRow(rows)
                 rows.AVPCC_DES = rows.GetValue("lu_desc")
                 curs.UpdateRow(rows)
                
            elif rows.GetValue("TENURE")=="PRIVATE":
                 rows.AVPCC_CODE = rows.GetValue("AVPCC")
                 curs.UpdateRow(rows)
                 rows.AVPCC_DES = rows.GetValue("AVPCC_Desc")
                 curs.UpdateRow(rows)
                
            else:
                 rows.AVPCC_CODE = "999"
                
                 rows.AVPCC_DES = "UNCLASSIFIED"
                 curs.UpdateRow(rows)
                
           
            rows = curs.Next()
           
        del curs
        print fc
        fc= fcList.Next()
0 Kudos
ChrisMathers
Deactivated User
You dont need to do <>None on your while loops. Python is smart enough to stop when it runs out of lines 😉
0 Kudos