<?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 Update Cursor using wildcards in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697870#M54099</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am new to Python and I'm having trouble writing a script to process some forestry data. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a feature class called "Survey" and in this feature class is a text field called CODE. The data in CODE are comma delimited, but contain varying amounts of text and are not necessarily in a specific order, for example: "M,C,1," or "Hw,D,Con,L,3". In this example C and Hw are host types, C = Conifer and Hw = Hardwood. What I'm trying to do is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. iterate through the rows looking for "*C,*" anywhere within the CODE field and if found&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. update another field, HOST, with "Conifer"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Oct 2012 13:04:38 GMT</pubDate>
    <dc:creator>JasonMoan</dc:creator>
    <dc:date>2012-10-03T13:04:38Z</dc:date>
    <item>
      <title>Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697870#M54099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am new to Python and I'm having trouble writing a script to process some forestry data. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a feature class called "Survey" and in this feature class is a text field called CODE. The data in CODE are comma delimited, but contain varying amounts of text and are not necessarily in a specific order, for example: "M,C,1," or "Hw,D,Con,L,3". In this example C and Hw are host types, C = Conifer and Hw = Hardwood. What I'm trying to do is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. iterate through the rows looking for "*C,*" anywhere within the CODE field and if found&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. update another field, HOST, with "Conifer"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help is greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 13:04:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697870#M54099</guid>
      <dc:creator>JasonMoan</dc:creator>
      <dc:date>2012-10-03T13:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697871#M54100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perhaps something like this would work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
surveyFc = 'Survey'
query = '"CODE" LIKE \'*C*\''

urows = arcpy.UpdateCursor(surveyFc, query)
for row in urows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("HOST", "Conifer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; urows.updateRow(row)
del row, urows
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:21:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697871#M54100</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T05:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697872#M54101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jason,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to take a good look at this pages for the selection by wildcard&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s500000033000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s500000033000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Untested, but probably your selection query will look something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'"thefield" LIKE'+"'"+thewildcard+"'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and for updating your values to your new field read this&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;and this&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/00170000004s000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Calculate_Field_examples/00170000004s000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope it helps&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Oct 2012 14:58:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697872#M54101</guid>
      <dc:creator>SebastianSantibanez</dc:creator>
      <dc:date>2012-10-03T14:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697873#M54102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure how all that hokey looking "\" syntax keeps getting propogated (oh yeah, model builder and the Help pages), but it is generally completely unneccessary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The wildcards of *, %, or ? depend of course on the database (and GIS data format) you are using...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This "should" work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Select anything with a 'C,' string patern in it (Assuming FGDB/SDE format) and make the HOST field = 'Conifer'
urows = arcpy.UpdateCursor(surveyFc, "CODE LIKE '%C,%')
for row in urows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("HOST", "Confier") #Note row.HOST = "Confier" also works
&amp;nbsp;&amp;nbsp;&amp;nbsp; urows.updateRow(row)
del row, urows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:21:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697873#M54102</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T05:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697874#M54103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great! This did work! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My question now is how would I set this up in an if statement? I think I'd need to change the urows variable first and then edit the For loop, but I can't seem to get the syntax right. What I'm trying to do is populate the HOST field with whatever HOST code is present in the CODE field. HOST is just one of many fields that I will be populating from the information in this CODE field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if CODE contains '%C,%' enter 'Conifer' in HOST&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else if CODE contains '%Hw,%' enter 'Hardwood' in HOST&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if CODE contains neither, HOST should be Null&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Not sure how all that hokey looking "\" syntax keeps getting propogated (oh yeah, model builder and the Help pages), but it is generally completely unneccessary.&lt;BR /&gt;&lt;BR /&gt;The wildcards of *, %, or ? depend of course on the database (and GIS data format) you are using...&lt;BR /&gt;&lt;BR /&gt;This "should" work:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Select anything with a 'C,' string patern in it (Assuming FGDB/SDE format) and make the HOST field = 'Conifer'
urows = arcpy.UpdateCursor(surveyFc, "CODE LIKE '%C,%')
for row in urows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("HOST", "Confier") #Note row.HOST = "Confier" also works
&amp;nbsp;&amp;nbsp;&amp;nbsp; urows.updateRow(row)
del row, urows&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:21:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697874#M54103</guid>
      <dc:creator>JasonMoan</dc:creator>
      <dc:date>2021-12-12T05:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor using wildcards</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697875#M54104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Doesn't use wildcards exactly, but how about something simple like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;urows = arcpy.UpdateCursor(surveyFc)
for row in urows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if 'C,' in updateRow.CODE
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("HOST", "Confier")
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif 'Hw,' in updateRow.CODE
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("HOST", "Hardwood")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setNull("HOST")
&amp;nbsp;&amp;nbsp;&amp;nbsp; urows.updateRow(row)
del row, urows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to use "wildcards" in a cursor, I think you would want to use a regular expression-based method: &lt;/SPAN&gt;&lt;A href="http://code.google.com/edu/languages/google-python-class/regular-expressions.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://code.google.com/edu/languages/google-python-class/regular-expressions.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:21:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-using-wildcards/m-p/697875#M54104</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T05:21:56Z</dc:date>
    </item>
  </channel>
</rss>

