<?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: Update &amp; Delete Cursor Functions in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185506#M14286</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Corrected Working Code:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt; work = arcpy.env.workspace = raw_input("Enter the full workspace path: ")&lt;BR /&gt; sType = "JUNIOR HIGH"&lt;BR /&gt; outFile = "output.shp"&lt;BR /&gt; arcpy.env.overwriteOutput = True&lt;BR /&gt; &lt;BR /&gt; def selectSchools(work,sType, outFile):&lt;BR /&gt; fc = "Schools.shp"&lt;BR /&gt; arcpy.MakeFeatureLayer_management(fc, "schoolslyr")&lt;BR /&gt; query = "\"FACILITY\" = '{0}'".format(sType)&lt;BR /&gt; arcpy.Select_analysis(fc, outFile, query)&lt;BR /&gt; &lt;BR /&gt; with arcpy.da.UpdateCursor(outFile, ['VERIFIED', 'NAME']) as uCursor:&lt;BR /&gt; for row in uCursor:&lt;BR /&gt; if row[0] != 'y':&lt;BR /&gt; print ("The following schools have not been verified: "), row[1]&lt;BR /&gt; if (row[0] != 'y'):&lt;BR /&gt; uCursor.deleteRow()&lt;BR /&gt; &lt;BR /&gt; selectSchools(work,sType,outFile) &lt;BR /&gt; &lt;BR /&gt;except Exception as e:&lt;BR /&gt; print "ERROR IN FUNCTION 'selectSchools' " + str("") # Prints Python-related errors&lt;BR /&gt; print arcpy.GetMessages() # Prints ArcPy-related errors&lt;BR /&gt; arcpy.AddError(e) # Adds errors to ArcGIS custom tool &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Feb 2017 18:00:24 GMT</pubDate>
    <dc:creator>AleahWorthem</dc:creator>
    <dc:date>2017-02-01T18:00:24Z</dc:date>
    <item>
      <title>Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185501#M14281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In my program:&lt;/P&gt;&lt;P&gt;-I am selecting only schools of the specified type based on the "FACILITY" field and creating new&lt;BR /&gt;feature class of the result.&lt;BR /&gt;- Deleting records from the resulting feature class from "Select" where the "Verified" field&lt;BR /&gt;does not equal "Y" (I need to use: Update cursor and deleteRow method)&lt;BR /&gt;- While deleting records, print the name of each deleted school&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code is not deleting the features that are not equal to "Y". And I am not sure how to print out the values that do not equal "Y".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;work = arcpy.env.workspace = "c:\Scripts\Lab 6 Data"&lt;BR /&gt;sType = "JUNIOR HIGH"&lt;BR /&gt;outFile = "output.shp"&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def selectSchools(work,sType, outFile):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = "Schools.shp"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(fc, "schoolslyr")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "\"FACILITY\" = '{0}'".format(sType)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(fc, outFile, query)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Select_Analysis layer tool completed!")&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where_c = "\"VERIFIED\" = 'y%'"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; update = arcpy.UpdateCursor(outFile, where_c)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = update.next()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in update:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; update.setValue(where_c)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; update.updateRow(row)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("The uppdate row was sucessful!")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("The following schools have not been verefied: ") &lt;BR /&gt; &lt;BR /&gt;selectSchools(work,sType,outFile))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Updated Code:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;work = arcpy.env.workspace = "c:\Scripts\Lab 6 Data"&lt;BR /&gt;sType = "JUNIOR HIGH"&lt;BR /&gt;outFile = "output.shp"&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;def selectSchools(work,sType, outFile):&lt;BR /&gt; fc = "Schools.shp"&lt;BR /&gt; arcpy.MakeFeatureLayer_management(fc, "schoolslyr")&lt;BR /&gt; query = "\"FACILITY\" = '{0}'".format(sType)&lt;BR /&gt; arcpy.Select_analysis(fc, outFile, query)&lt;BR /&gt; arcpy.AddMessage("Select_Analysis layer tool completed!")&lt;BR /&gt; &lt;BR /&gt; with arcpy.da.UpdateCursor(outFile, ['VERIFIED', 'NAME']) as uCursor:&lt;BR /&gt; for row in uCursor:&lt;BR /&gt; if row[0].upper() != 'y%':&lt;BR /&gt; print row[1]&lt;BR /&gt; if (row[0].upper() != 'y%'):&lt;BR /&gt; uCursor.deleteRow()&lt;BR /&gt;selectSchools(work,sType,outFile)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2017 02:06:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185501#M14281</guid>
      <dc:creator>AleahWorthem</dc:creator>
      <dc:date>2017-02-01T02:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185502#M14282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;perhaps you want&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'yes'&lt;/SPAN&gt;
&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;upper&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Y'&lt;/SPAN&gt;
&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This example just checks to see if the first character is y or Y... if you want those that don't ... just use ... != ... in place of equality&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185502#M14282</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T09:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185503#M14283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a way to write this in a 'for' or 'while' loop using either update cursor or deleteRow()?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2017 14:13:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185503#M14283</guid>
      <dc:creator>AleahWorthem</dc:creator>
      <dc:date>2017-02-01T14:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185504#M14284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;of course... via demonstration&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;a &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'yea'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'neay'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Yup'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Nope'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'yes'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Yes'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; value &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; a&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;value&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;upper&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="string token"&gt;'Y'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Y"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"no"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

yielding
 Y
no
Y
no
Y
Y&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:24:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185504#M14284</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T09:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185505#M14285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My updated code is now printing out the names of the facilities that do not equal "y" which is good. But when I try to delete those same names from my rows, it deletes all of my records.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2017 16:43:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185505#M14285</guid>
      <dc:creator>AleahWorthem</dc:creator>
      <dc:date>2017-02-01T16:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Update &amp; Delete Cursor Functions</title>
      <link>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185506#M14286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Corrected Working Code:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt; work = arcpy.env.workspace = raw_input("Enter the full workspace path: ")&lt;BR /&gt; sType = "JUNIOR HIGH"&lt;BR /&gt; outFile = "output.shp"&lt;BR /&gt; arcpy.env.overwriteOutput = True&lt;BR /&gt; &lt;BR /&gt; def selectSchools(work,sType, outFile):&lt;BR /&gt; fc = "Schools.shp"&lt;BR /&gt; arcpy.MakeFeatureLayer_management(fc, "schoolslyr")&lt;BR /&gt; query = "\"FACILITY\" = '{0}'".format(sType)&lt;BR /&gt; arcpy.Select_analysis(fc, outFile, query)&lt;BR /&gt; &lt;BR /&gt; with arcpy.da.UpdateCursor(outFile, ['VERIFIED', 'NAME']) as uCursor:&lt;BR /&gt; for row in uCursor:&lt;BR /&gt; if row[0] != 'y':&lt;BR /&gt; print ("The following schools have not been verified: "), row[1]&lt;BR /&gt; if (row[0] != 'y'):&lt;BR /&gt; uCursor.deleteRow()&lt;BR /&gt; &lt;BR /&gt; selectSchools(work,sType,outFile) &lt;BR /&gt; &lt;BR /&gt;except Exception as e:&lt;BR /&gt; print "ERROR IN FUNCTION 'selectSchools' " + str("") # Prints Python-related errors&lt;BR /&gt; print arcpy.GetMessages() # Prints ArcPy-related errors&lt;BR /&gt; arcpy.AddError(e) # Adds errors to ArcGIS custom tool &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2017 18:00:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-delete-cursor-functions/m-p/185506#M14286</guid>
      <dc:creator>AleahWorthem</dc:creator>
      <dc:date>2017-02-01T18:00:24Z</dc:date>
    </item>
  </channel>
</rss>

