<?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: arcpy.da.SearchCursor TypeError: 'field_names' must be string.... in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1490974#M70803</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/4413"&gt;@DavidSolari&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all so much for your input!&lt;/P&gt;&lt;P&gt;I went with David's solution as it is simplified from the original and makes more sense to my inexperienced eye.&lt;/P&gt;&lt;P&gt;In addition, the exported portal layer resulted in the Field Name being in all lower case so "Name" was not recognized. I received and error that asked if I meant "name" so I checked, and sure enough that was that problem.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Portal.jpg" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/106887iF9864D7FDA2697BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Portal.jpg" alt="Portal.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 20:04:47 GMT</pubDate>
    <dc:creator>ElisseDeleissegues1</dc:creator>
    <dc:date>2024-06-12T20:04:47Z</dc:date>
    <item>
      <title>arcpy.da.SearchCursor TypeError: 'field_names' must be string....</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1487536#M70759</link>
      <description>&lt;P&gt;This is a portion of an inherited code, we have recently upgraded to a more current Enterprise.&lt;/P&gt;&lt;P&gt;The code worked on the older Enterprise version, he rest of the code has been updated and seems to be running fine when run as individual cells.&lt;/P&gt;&lt;P&gt;The Error message:&lt;/P&gt;&lt;PRE&gt;In  &lt;SPAN class=""&gt;[12]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;13&lt;/SPAN&gt;:    &lt;SPAN class=""&gt;with&lt;/SPAN&gt; arcpy.da.SearchCursor(fc, fields, query) &lt;SPAN class=""&gt;as&lt;/SPAN&gt; row:

&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;: 'field_names' must be string or non empty sequence of strings
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Extract Tax Parcels from Parcel Editing (Feature Service on Portal)

source = r"UPDATEDENTERPRISE/HOSTED//FEATURELAYER/FeatureServer/0"
fc = r"UPDATEDENTERPRISE/HOSTED//FEATURELAYER/FeatureServer/0"
CSVFile = r"S:\LOCALSERVERPATH\GISDATA.csv"
query = """("Name" NOT LIKE BLAHBLAHBLAH)"""

fields = [f.name for f in arcpy.ListFields(fc) if f.name in ('Name')]

with open(CSVFile, 'w') as f:
    f.write(','.join(fields)+'\n') #csv headers
    with arcpy.da.SearchCursor(fc, fields, query) as row:
        for row in rows:
            f.write(','.join([str(r) for r in row])+'\n') 
print("CSV File Created for GIS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've been looking through StackExchange, StackOverflow, Esri Community, etc. for a couple of days now and have tried variations on suggestions but continue to get the same error.&lt;/P&gt;&lt;P&gt;Any suggestions will be very welcome. I am new to this.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jun 2024 01:21:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1487536#M70759</guid>
      <dc:creator>ElisseDeleissegues1</dc:creator>
      <dc:date>2024-06-08T01:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.SearchCursor TypeError: 'field_names' must be string....</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1487574#M70760</link>
      <description>&lt;P&gt;So, field_names required either one field or a list with a length greater than 0.&lt;/P&gt;&lt;P&gt;You appear to be feeding it a list, so the next question is: does that list have anything in it?&lt;/P&gt;&lt;P&gt;It’s possible that your fields don’t match the if statement on line 8. I’d check that out.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jun 2024 03:05:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1487574#M70760</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-06-08T03:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.SearchCursor TypeError: 'field_names' must be string....</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1488262#M70772</link>
      <description>&lt;P&gt;On line 8 where you're creating the &lt;FONT face="courier new,courier"&gt;fields&lt;/FONT&gt; list, the last part where it's checking if f.name in ('Name') seems weird. Are you intending to only make a list with exactly one value of 'Name'? As-is, I think like 8 is actually only getting fields that are "N", "a", "m", "e". If you are wanting to check equality, use an equals:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = [f.name for f in arcpy.ListFields(fc) if f.name = 'Name']&lt;/LI-CODE&gt;&lt;P&gt;If you are wanting to check equality on a number of possible matches, then that tuple needs a comma after the first item:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = [f.name for f in arcpy.ListFields(fc) if f.name in ('Name',)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Or just use a list instead of a tuple:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = [f.name for f in arcpy.ListFields(fc) if f.name in ['Name']]&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 10 Jun 2024 14:12:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1488262#M70772</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-06-10T14:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.SearchCursor TypeError: 'field_names' must be string....</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1488305#M70774</link>
      <description>&lt;P&gt;That snippet is an error prone and roundabout way of doing:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Extract Tax Parcels from Parcel Editing (Feature Service on Portal)

field_name = "Name"

source = r"UPDATEDENTERPRISE/HOSTED//FEATURELAYER/FeatureServer/0"
fc = r"UPDATEDENTERPRISE/HOSTED//FEATURELAYER/FeatureServer/0"
CSVFile = r"S:\LOCALSERVERPATH\GISDATA.csv"
query = f"""("{field_name}" NOT LIKE BLAHBLAHBLAH)"""

with open(CSVFile, 'w') as f:
    f.write(field_name + '\n') #csv header
    with arcpy.da.SearchCursor(fc, field_name, query) as rows:
        for value, in rows:  # Deconstruct the single-item tuple into a single variable using the for loop
            f.write(value + '\n') 
print("CSV File Created for GIS")&lt;/LI-CODE&gt;&lt;P&gt;This makes the intent clearer and you'll get a more obvious error if the dataset lacks a "Name" field.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 15:33:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1488305#M70774</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2024-06-10T15:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.SearchCursor TypeError: 'field_names' must be string....</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1490974#M70803</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/4413"&gt;@DavidSolari&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all so much for your input!&lt;/P&gt;&lt;P&gt;I went with David's solution as it is simplified from the original and makes more sense to my inexperienced eye.&lt;/P&gt;&lt;P&gt;In addition, the exported portal layer resulted in the Field Name being in all lower case so "Name" was not recognized. I received and error that asked if I meant "name" so I checked, and sure enough that was that problem.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Portal.jpg" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/106887iF9864D7FDA2697BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Portal.jpg" alt="Portal.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 20:04:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-typeerror-field-names-must/m-p/1490974#M70803</guid>
      <dc:creator>ElisseDeleissegues1</dc:creator>
      <dc:date>2024-06-12T20:04:47Z</dc:date>
    </item>
  </channel>
</rss>

