<?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: Checking Data Types in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084874#M61913</link>
    <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Returns a list of Field objects, you've grabbed the name property, but you can also access type:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for field in arcpy.ListFields(os.path.join(location,prefix+table)):
    print(field.name, field.type)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Aug 2021 12:49:57 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2021-08-02T12:49:57Z</dc:date>
    <item>
      <title>Checking Data Types</title>
      <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084856#M61911</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to create a script that checks the column name and datatype. Right now I can grab the column name but would also like to return the datatype to check them both at the same time.&lt;/P&gt;&lt;P&gt;for table in tables:&lt;BR /&gt;fields = [f.name for f in arcpy.ListFields(os.path.join(location,prefix+table))]&lt;/P&gt;&lt;P&gt;if table == 'Customers':&lt;BR /&gt;for field in ['FirstName', 'LastName','Location']:&lt;BR /&gt;if field not in fields:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(table + '.' + field + ' - Incorrect)&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;print(table + '.' + field + ' - Correct')&lt;/P&gt;&lt;P&gt;I have a number of tables which I'm planning on running a check against for column name and datatype if possible. If anyone has done something similar or could help me with understanding how to check the datatype as well I would greatly appreciate it.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 12:18:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084856#M61911</guid>
      <dc:creator>Timmon</dc:creator>
      <dc:date>2021-08-02T12:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Checking Data Types</title>
      <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084874#M61913</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Returns a list of Field objects, you've grabbed the name property, but you can also access type:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for field in arcpy.ListFields(os.path.join(location,prefix+table)):
    print(field.name, field.type)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 12:49:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084874#M61913</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-08-02T12:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Checking Data Types</title>
      <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084877#M61914</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The fields have properties you can access as mentioned here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/field.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/field.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for each field returned by ListFields, you want check that field.name is in&amp;nbsp;&lt;SPAN&gt;['FirstName', 'LastName','Location']?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From there, you want to do an additional check to see that field.type matches the corresponding field type?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would probably modify the approach to make it a little easier. A simple list of dictionaries or objects will do. So you'd have [{"field": "FirstName", "type":&amp;nbsp; "whatever"}, {"field": "LastName", "type":&amp;nbsp; "whatever"}, {"field": "Location", "type":&amp;nbsp; "whatever"}]. If you can get the field objects for the thing you're checking against that might be easier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 12:54:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084877#M61914</guid>
      <dc:creator>emedina</dc:creator>
      <dc:date>2021-08-02T12:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Checking Data Types</title>
      <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084881#M61915</link>
      <description>&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 13:03:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084881#M61915</guid>
      <dc:creator>Timmon</dc:creator>
      <dc:date>2021-08-02T13:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Checking Data Types</title>
      <link>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084882#M61916</link>
      <description>&lt;P&gt;I see so have the correct values I'm checking against in a list of objects to compare against. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 13:04:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-data-types/m-p/1084882#M61916</guid>
      <dc:creator>Timmon</dc:creator>
      <dc:date>2021-08-02T13:04:59Z</dc:date>
    </item>
  </channel>
</rss>

