<?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: Delete all table records with special character, # , ' in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229856#M17802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A different approach would be to use a SQL WHERE clause on your update cursor so that all records already meet the criteria, then you can just delete them without having to check them in Python.&lt;/P&gt;&lt;P&gt;sql = "FIELD LIKE '%'%' or FIELD LIKE '%#%'"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 May 2020 18:10:34 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2020-05-18T18:10:34Z</dc:date>
    <item>
      <title>Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229850#M17796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature class table that i need to delete the rows with special characters of # , ' or other certain special characters. I have tried the following but nothing happens so I am not coding it correctly, I am in need of some help please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;A2 = "ArcSDE Personal Server/featureclass"

# sql SubName LIKE '%#'
with arcpy.da.UpdateCursor(A2 , ["OBJECTID","Field"]) as cursor:  
    for row in cursor:      
        if row[1] in ["'", "#"]:
            print ("Deleting record: 'OBJECTID' = {}".format(row[0])) 
            cursor.deleteRow()

&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:10:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229850#M17796</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-12-11T11:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229851#M17797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does Field only contain a special character or are there other characters there as well?&amp;nbsp; Your line #6 is defined such that the contents of the field is only a single quote or a hash tag.&amp;nbsp; If you have other characters in that field you may want to consider some regular expression searching.&amp;nbsp; Take a look here:&amp;nbsp;&amp;nbsp;&lt;A class="link-titled" href="https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/" title="https://www.geeksforgeeks.org/python-program-check-string-contains-special-character/"&gt;Program to check if a string contains any special character - GeeksforGeeks&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 17:17:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229851#M17797</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-05-18T17:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229852#M17798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It does but I am looking to delete rows with just hash tag and apostrophe.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 17:33:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229852#M17798</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2020-05-18T17:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229853#M17799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then your line 6 is backwards.&amp;nbsp; See if this works:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;if "'" or "#" in row[1]:
   do something&lt;SPAN class="line-numbers-rows"&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 11:10:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229853#M17799</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T11:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229854#M17800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joe, that won't work.&amp;nbsp; It would have to be written&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;or&lt;/SPAN&gt; "&lt;SPAN class="comment token"&gt;#" in row[1]:‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 18:06:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229854#M17800</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-18T18:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229855#M17801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yeah.&amp;nbsp; that sounds more better!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 18:08:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229855#M17801</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-05-18T18:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229856#M17802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A different approach would be to use a SQL WHERE clause on your update cursor so that all records already meet the criteria, then you can just delete them without having to check them in Python.&lt;/P&gt;&lt;P&gt;sql = "FIELD LIKE '%'%' or FIELD LIKE '%#%'"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2020 18:10:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229856#M17802</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-18T18:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all table records with special character, # , '</title>
      <link>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229857#M17803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know your question has already been answered but I couldn't resist sharing a couple little tricks I use. First, consider using the @ &lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/updatecursor-class.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;field name token&lt;/A&gt; options to access Esri fields more reliably.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;A2 &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"OID@"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Field"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; oid&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; field &lt;SPAN class="operator token"&gt;or&lt;/SPAN&gt; "&lt;SPAN class="comment token"&gt;#" in field:&lt;/SPAN&gt;
            &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;"Deleting record: 'OBJECTID' = {}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;oid&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Also used in the sample above is a method called &lt;A href="https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences" rel="nofollow noopener noreferrer" target="_blank"&gt;sequence unpacking&lt;/A&gt; to easily assign variable names to your cursor row indexes (field values). This works best with only a few fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have many fields in your cursor, you can use this helper function to &lt;A href="https://arcpy.wordpress.com/2012/07/12/getting-arcpy-da-rows-back-as-dictionaries/" rel="nofollow noopener noreferrer" target="_blank"&gt;make a dictionary of the values&lt;/A&gt;&amp;nbsp;so it's cleaner to access them instead of using the row index like &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;row[1]&lt;/SPAN&gt;.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;A2 &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"aField"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"anotherField"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"moreField"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; row_as_dict&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cursor&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"'"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"aField"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;or&lt;/SPAN&gt; "&lt;SPAN class="comment token"&gt;#" in row["anotherField"]:&lt;/SPAN&gt;
            &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;"Deleting record: 'moreField' = {}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"moreField"&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;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;row_as_dict&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;data&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; data&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;yield&lt;/SPAN&gt; OrderedDict&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;zip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fields&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&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;/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 11:10:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-all-table-records-with-special-character/m-p/229857#M17803</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-11T11:10:40Z</dc:date>
    </item>
  </channel>
</rss>

