<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Point in Polygon and Calculate Field crashes on conditional Statement in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/point-in-polygon-and-calculate-field-crashes-on/m-p/209595#M16224</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I created a script to calculate some fields in a number polygon feature classes. It also counts the points within each polygon and places the count into a field (ASSOC_PTS) for each polygon record. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In only one of the polygon feature classes, there is an extra field (SUBREG) that is not in any of the others. I borrowed a conditional statement (the first 'try' statement) to check for the extra field and to calculate or ignore it as needed. I borrowed the statement from another script I made for some point feature classes that have the same senario with the extra field. It works in the point script, but doesn't in the polygon script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error message is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'geoprocessing list object' object is not iterable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed the geoprocessing object from&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems to allow the condition statement to pass successfully, but then the script crashes on the loop portion at the bottom which iterates through the rows of the polygon feature class and counts all the points from a point feature class (the second 'try' statement) and then places the count into a field called ASSOC_PTS. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Object: Error in executing tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Before I added the conditional statement, the point in polygon script works perfectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have feeling part of the code is recognized in 9.3 and the rest is recognized in an older version, but I'm not sure. Does anyone have suggestions why it crashes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import native arcgisscripting module
import arcgisscripting, sys
# Create the geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

# Table and field name inputs
POINT = sys.argv[1]
POLYGON = sys.argv[2]
SITE = sys.argv[3]
DATESURVEY = sys.argv[4]

gp.AddMessage("Enter Site Name into SITE field...")
# Process: Calculate Field - SITE...
gp.CalculateField_management(POLYGON, "SITE", SITE, "VB", "")

gp.AddMessage("Updating DATE_SURVEY field with survey date...")
# Process: Calculate Field - DATE_SURVEY...
gp.CalculateField_management(POLYGON, "DATE_SURVEY", DATESURVEY, "VB", "")

gp.AddMessage("Updating SOURCE field with ~Company~...")
# Process: Calculate Field - SOURCE...
gp.CalculateField_management(POLYGON, "SOURCE", "\"Company\"", "VB", "")


#Loop through fields to determine if SUBREG field exists. If it does, then calculate with the string "Boreal Mixedwood".
#If it doesn't exist, then finish the script

gp.AddMessage("Checking for SUBREG field")

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; thefieldlist = gp.ListFields(POLYGON)
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in thefieldlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "SUBREG" in field.name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management(POLYGON, "SUBREG", "\"Boreal Mixedwood\"", "VB", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("SUBREG has been found and calculated")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass


except Exception, errMsg:

#&amp;nbsp; If we have messages of severity error (2), we assume a GP tool raised it,
#&amp;nbsp; so we'll output that.&amp;nbsp; Otherwise, we assume we raised the error and the
#&amp;nbsp; information is in errMsg.

&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.GetMessages(2):&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(gp.GetMessages(2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(str(errMsg))

del thefieldlist



# Converts unselectable feature class into a selectable feature layer
gp.MakeFeatureLayer(POINT,"point")
gp.MakeFeatureLayer(POLYGON,"polygon")

rows = gp.SearchCursor("polygon")
row = rows.Next()

gp.AddMessage("Calculating Points in Polgons...")


try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select each record inside of the polygon feature class&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPoly = gp.SelectLayerByAttribute("polygon", "NEW_SELECTION", "\"OBJECTID\" =" + str(row.OBJECTID))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all the point that are inside of the polygon record
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPts = gp.SelectLayerByLocation("point", "WITHIN", SelPoly, 0, "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Count the points that are in each polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetCount = gp.GetCount_management(SelPts)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Calculate the ASSOC_PTS field with the counted points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("polygon", "ASSOC_PTS", GetCount, "VB", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Move to the next row&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()


except Exception, errMsg:

#&amp;nbsp; If we have messages of severity error (2), we assume a GP tool raised it,
#&amp;nbsp; so we'll output that.&amp;nbsp; Otherwise, we assume we raised the error and the
#&amp;nbsp; information is in errMsg.

&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.GetMessages(2):&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(gp.GetMessages(2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(str(errMsg))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del row
del rows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Apr 2011 21:47:30 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2011-04-20T21:47:30Z</dc:date>
    <item>
      <title>Point in Polygon and Calculate Field crashes on conditional Statement</title>
      <link>https://community.esri.com/t5/python-questions/point-in-polygon-and-calculate-field-crashes-on/m-p/209595#M16224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I created a script to calculate some fields in a number polygon feature classes. It also counts the points within each polygon and places the count into a field (ASSOC_PTS) for each polygon record. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In only one of the polygon feature classes, there is an extra field (SUBREG) that is not in any of the others. I borrowed a conditional statement (the first 'try' statement) to check for the extra field and to calculate or ignore it as needed. I borrowed the statement from another script I made for some point feature classes that have the same senario with the extra field. It works in the point script, but doesn't in the polygon script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error message is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'geoprocessing list object' object is not iterable&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed the geoprocessing object from&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems to allow the condition statement to pass successfully, but then the script crashes on the loop portion at the bottom which iterates through the rows of the polygon feature class and counts all the points from a point feature class (the second 'try' statement) and then places the count into a field called ASSOC_PTS. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Object: Error in executing tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Before I added the conditional statement, the point in polygon script works perfectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have feeling part of the code is recognized in 9.3 and the rest is recognized in an older version, but I'm not sure. Does anyone have suggestions why it crashes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import native arcgisscripting module
import arcgisscripting, sys
# Create the geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

# Table and field name inputs
POINT = sys.argv[1]
POLYGON = sys.argv[2]
SITE = sys.argv[3]
DATESURVEY = sys.argv[4]

gp.AddMessage("Enter Site Name into SITE field...")
# Process: Calculate Field - SITE...
gp.CalculateField_management(POLYGON, "SITE", SITE, "VB", "")

gp.AddMessage("Updating DATE_SURVEY field with survey date...")
# Process: Calculate Field - DATE_SURVEY...
gp.CalculateField_management(POLYGON, "DATE_SURVEY", DATESURVEY, "VB", "")

gp.AddMessage("Updating SOURCE field with ~Company~...")
# Process: Calculate Field - SOURCE...
gp.CalculateField_management(POLYGON, "SOURCE", "\"Company\"", "VB", "")


#Loop through fields to determine if SUBREG field exists. If it does, then calculate with the string "Boreal Mixedwood".
#If it doesn't exist, then finish the script

gp.AddMessage("Checking for SUBREG field")

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; thefieldlist = gp.ListFields(POLYGON)
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in thefieldlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "SUBREG" in field.name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management(POLYGON, "SUBREG", "\"Boreal Mixedwood\"", "VB", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("SUBREG has been found and calculated")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass


except Exception, errMsg:

#&amp;nbsp; If we have messages of severity error (2), we assume a GP tool raised it,
#&amp;nbsp; so we'll output that.&amp;nbsp; Otherwise, we assume we raised the error and the
#&amp;nbsp; information is in errMsg.

&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.GetMessages(2):&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(gp.GetMessages(2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(str(errMsg))

del thefieldlist



# Converts unselectable feature class into a selectable feature layer
gp.MakeFeatureLayer(POINT,"point")
gp.MakeFeatureLayer(POLYGON,"polygon")

rows = gp.SearchCursor("polygon")
row = rows.Next()

gp.AddMessage("Calculating Points in Polgons...")


try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select each record inside of the polygon feature class&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPoly = gp.SelectLayerByAttribute("polygon", "NEW_SELECTION", "\"OBJECTID\" =" + str(row.OBJECTID))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select all the point that are inside of the polygon record
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPts = gp.SelectLayerByLocation("point", "WITHIN", SelPoly, 0, "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Count the points that are in each polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetCount = gp.GetCount_management(SelPts)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Calculate the ASSOC_PTS field with the counted points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("polygon", "ASSOC_PTS", GetCount, "VB", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Move to the next row&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()


except Exception, errMsg:

#&amp;nbsp; If we have messages of severity error (2), we assume a GP tool raised it,
#&amp;nbsp; so we'll output that.&amp;nbsp; Otherwise, we assume we raised the error and the
#&amp;nbsp; information is in errMsg.

&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.GetMessages(2):&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(gp.GetMessages(2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(str(errMsg))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del row
del rows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Apr 2011 21:47:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-in-polygon-and-calculate-field-crashes-on/m-p/209595#M16224</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2011-04-20T21:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Point in Polygon and Calculate Field crashes on conditional Statement</title>
      <link>https://community.esri.com/t5/python-questions/point-in-polygon-and-calculate-field-crashes-on/m-p/209596#M16225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Two points:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By adding try - except statements without fixing the error in question, you hide vital information (like the traceback) that is very useful for debugging purposes.&amp;nbsp; Don't be afraid of unhandled exceptions and tracebacks, learn to read them and fix the problem behind them instead of hiding them. If you remove both your try - except statements in your code you will get the line number of the origin of the exception. When you have done that, and still can't pinpoint the reason of the crash, you can post the edited code, together with the full traceback and it will be much easier to help you fix the problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my opinion there are basically two reasons for try - except: To handle expected errors and exceptions that can be fixed in the code, and to log error messages. In the latter case the exception should be reraised with an empty raise statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My second point is regarding your loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A much cleaner and less error prone pattern for looping over search cursors in 9.3 instead of what Esri teaches in there samples is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = gp.SearchCursor('some_feature_class')
row_count = 0
for row in iter(rows.Next, None):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # inside loop processing goes here
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.Name # or whatever
&amp;nbsp;&amp;nbsp;&amp;nbsp; row_count += 1
# after loop processing goes here
print row_count
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:20:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/point-in-polygon-and-calculate-field-crashes-on/m-p/209596#M16225</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2021-12-11T10:20:20Z</dc:date>
    </item>
  </channel>
</rss>

