<?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 Re: an example of how not to use a cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546428#M42622</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are on the right track Nathan. You code would be much more efficient if it was structured something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Returns a feature layer composed of the features in 'parentFC' that
#share the same "MY_ID" values as those in 'lookupTbl'
lookupIds = [r.MY_ID for r in arcpy.SearchCursor(lookupTbl)]
arcpy.MakeFeatureLayer_managment(parentFC, "lyr", "MY_ID in (" + str(lookupIds)[1:-1] + ")")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 23:39:11 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2021-12-11T23:39:11Z</dc:date>
    <item>
      <title>an example of how not to use a cursor</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546422#M42616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have written a script to loop through all rows in a specified field in a table and 'add to selection' all the features that match. If i run the lines individually, outside of the for loop then it works. When I run it in the loop it runs through about 90 and then gives the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'NoneType' object has no attribute 'getValue error &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have seen this topic in several other forum posts but none with a resolution. Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") fcList = arcpy.mapping.ListLayers(mxd) jTable = "C:/Users/nwuenstel/Desktop/LocalP/Error_Process/Bangladesh_joinsV.csv" getvalField = "UID5" rows = arcpy.SearchCursor(jTable)&amp;nbsp; for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next() &amp;nbsp;&amp;nbsp;&amp;nbsp; varUID = str(row.getValue(getvalField)) &amp;nbsp;&amp;nbsp;&amp;nbsp; whereExpr = "\"UID\" = '%s'" % varUID &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Bng_Line_C", "ADD_TO_SELECTION", whereExpr ) &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2012 16:30:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546422#M42616</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2012-11-14T16:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: 'NoneType' object has no attribute 'getValue error after about 90 iterations</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546423#M42617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is not what cursors are for. Do not do this. Something like the following would be better, but you'd have to explain your process a little more.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

jTable = "C:/Users/nwuenstel/Desktop/LocalP/Error_Process/Bangladesh_joinsV.csv"
outTable = "in_memory\temptable"
whereExpr = "\"UID\" = 'UID5'"
arcpy.MakeTableView_management(jTable, outTable, whereExpr)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you still need to know how to process null row values, it goes like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;sCursor = arcpy.SearchCursor(table)
for row in sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not row.Field:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "it's null"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "it's not null"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546423#M42617</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T23:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: 'NoneType' object has no attribute 'getValue error after about 90 iterations</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546424#M42618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your response Matthew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am basically trying to join a table&amp;nbsp; ("jTable") to a shapefile ("Bng_Line_C", listed in the select by attributes line) usint the "UID5" field and keeping only matching records. And then export the matching records to a new shapefile. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am on day three of using python and was just using my very rudimentary knowledge of cursors to return variables from a field. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So using your recommendations I can now create a table. I am guessing that the table view should actually be a layer file of the shapefile ("Bng_Line_C") and not the join table ("jTable") so that the output will contain the geometry. Is that right? So how could I join the table to the shapefile using arcpy?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; I think i will be able to create the shapes using the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
setNum = "5"
env.workspace = "C:/Users/nwuenstel/Desktop/LocalP/Error_Process/Consolidated Shapes"
outPath1 = "C:/Users/nwuenstel/Desktop/LocalP/Error_Process/om_shapes/poly0"
arcpy.CopyFeatures_management("Bangladesh_Poly_Consolidated", outPath1 + setNum)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also thanks for the suggestion on how to handle null values. i will likely need that in the near future.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546424#M42618</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2021-12-11T23:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: 'NoneType' object has no attribute 'getValue error after about 90 iterations</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546425#M42619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Then you should just join them together and export matching records. Use the add join tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Add_Join/001700000064000000/" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Add_Join/001700000064000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2012 18:36:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546425#M42619</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-11-14T18:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: 'NoneType' object has no attribute 'getValue error after about 90 iterations</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546426#M42620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again Matthew,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have seen several examples, including in the Arc10 Desktop help where a search cursor is used with a for loop to return values for a field for each row. If this is not the intended function of a cursor then what are the primary uses for cursors?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In any case i consider this as resolved and then change the topic.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Nathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2012 19:46:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546426#M42620</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2012-11-14T19:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: 'NoneType' object has no attribute 'getValue error after about 90 iterations</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546427#M42621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;a search cursor is used with a for loop to return values for a field for each row&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, that is exactly what a search cursors is for. However, that is not what you are doing. You are matching records between two datasets, which is a join. The biggest red flag that you are likely using a cursor wrong is if you have arcpy functions within your loop. Arcpy functions are geared towards processing on an entire dataset, not on a row by row basis.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Nov 2012 20:06:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546427#M42621</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-11-14T20:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: an example of how not to use a cursor</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546428#M42622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are on the right track Nathan. You code would be much more efficient if it was structured something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Returns a feature layer composed of the features in 'parentFC' that
#share the same "MY_ID" values as those in 'lookupTbl'
lookupIds = [r.MY_ID for r in arcpy.SearchCursor(lookupTbl)]
arcpy.MakeFeatureLayer_managment(parentFC, "lyr", "MY_ID in (" + str(lookupIds)[1:-1] + ")")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546428#M42622</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T23:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: an example of how not to use a cursor</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546429#M42623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;...and to exclude any Nulls in the lookup table I think could look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lookupIds = [r.MY_ID for r in arcpy.SearchCursor(lookupTbl) if r.MY_ID != None]
arcpy.MakeFeatureLayer_managment(parentFC, "lyr", "MY_ID in (" + str(lookupIds)[1:-1] + ")")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546429#M42623</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T23:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: an example of how not to use a cursor</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546430#M42624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you both for your suggestions. I was able to get this to work using the join function. I will try some of the lookups too to see if that works. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2012 12:19:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546430#M42624</guid>
      <dc:creator>nathanwuenstel</dc:creator>
      <dc:date>2012-11-15T12:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: an example of how not to use a cursor</title>
      <link>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546431#M42625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I agree with everything Matthew and Chris have said. This is not how you should use a cursor.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That said, for future reference... the problem with your original code is you are looping through every row (for row in rows) but then advancing the cursor to the following row (row = rows.next()) without actually processing the current row. When you get to the last row, rows.next() will return None and None types do not have getValue methods which is why your script bombs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next() #&amp;lt;----- This is the problem.&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:39:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/an-example-of-how-not-to-use-a-cursor/m-p/546431#M42625</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T23:39:17Z</dc:date>
    </item>
  </channel>
</rss>

