<?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 Store fieldnames in a string variable in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398356#M80655</link>
    <description>&lt;P&gt;Usually one can get the list of field/column names using the following code. Now, I would like to store the field names as strings in a variable. How can I do this?&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var = ("Field 1", "Field2", "Field.3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another try (does not work either):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;for field in fields:
    var = str(field.name)&lt;/LI-CODE&gt;&lt;P&gt;Current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = arcpy.ListFields('df')
# Show column names
for field in fields:
    print(field.name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2024 13:25:56 GMT</pubDate>
    <dc:creator>Ed_</dc:creator>
    <dc:date>2024-03-20T13:25:56Z</dc:date>
    <item>
      <title>Store fieldnames in a string variable</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398356#M80655</link>
      <description>&lt;P&gt;Usually one can get the list of field/column names using the following code. Now, I would like to store the field names as strings in a variable. How can I do this?&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var = ("Field 1", "Field2", "Field.3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another try (does not work either):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;for field in fields:
    var = str(field.name)&lt;/LI-CODE&gt;&lt;P&gt;Current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = arcpy.ListFields('df')
# Show column names
for field in fields:
    print(field.name)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 13:25:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398356#M80655</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-20T13:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Store fieldnames in a string variable</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398393#M80658</link>
      <description>&lt;P&gt;I've taken what you asked for quite literally (i.e. replaced single speech-marks with doubles and square brackets with curly) hence the multiple replace operations on the final variable but I think it should achieve what you're after&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = arcpy.ListFields('df')
fieldlist = []
for field in fields:
  fieldlist.append(field.name)

var = str(fieldlist).replace("'", '"').replace("[", "(").replace("]", ")")
print var&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 13:38:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398393#M80658</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-03-20T13:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Store fieldnames in a string variable</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398414#M80664</link>
      <description>&lt;P&gt;The major issue you are having is that arcpy.ListFields returns just that, fields or field objects, and not field names.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var = [field.name for field in arcpy.ListFields('df')]&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 14:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398414#M80664</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-03-20T14:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Store fieldnames in a string variable</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398417#M80665</link>
      <description>&lt;P&gt;Hi Joshua, I might ping you, if you have sometime, since now I am trying to combine the code in your reply with the code you helped with earlier in the split comma separated values post. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 14:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/store-fieldnames-in-a-string-variable/m-p/1398417#M80665</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-03-20T14:10:41Z</dc:date>
    </item>
  </channel>
</rss>

