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])
arcpy cursor for-loop
add a comment |
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])
arcpy cursor for-loop
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
Nov 27 at 10:14
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
Nov 27 at 10:26
add a comment |
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])
arcpy cursor for-loop
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
arcpy cursor for-loop
edited Nov 27 at 11:05
PolyGeo♦
52.9k1779237
52.9k1779237
asked Nov 27 at 9:59
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
Nov 27 at 10:14
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
Nov 27 at 10:26
add a comment |
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
Nov 27 at 10:14
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
Nov 27 at 10:26
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
Nov 27 at 10:14
BERA's answer will solve your problem, but this double loop will be quite inefficient. It would probably work better with a dictionnary.
– radouxju
Nov 27 at 10:14
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
Nov 27 at 10:26
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
Nov 27 at 10:26
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 27 at 10:10
answered Nov 27 at 10:05
BERA
13.7k51739
13.7k51739
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
Nov 27 at 10:14
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
Nov 27 at 10:26