<?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: Do the following python field checks exist? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267608#M67082</link>
    <description>&lt;P&gt;This should get you started.&amp;nbsp; Change out the defaults per field type in the dictionary.&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;import datetime
# Create a list of fields using the ListFields function
fields = arcpy.ListFields(in_Table)

defaultVal = {'Blob': 'stuff',
         'Date': datetime.datetime.now(),
         'Double': 54.2,
         'Geometry': 'Geometry',
         'GlobalID': 'Global ID',
         'Guid': 'Guid',
         'Integer': 23,
         'OID': 'Object ID',
         'Raster': 'Raster',
         'Single': 1,
         'SmallInteger': 3,
         'String': 'Text'}

# Iterate through the list of fields
for field in fields:
    # Not sure what Default value you are checking, but if they are different
    # for field types, you can set a dictionary and get it from there.
    
    print(f"Type: {field.type}")
    if field.defaultValue != defaultVal.get(field.defaultValue): # second param there is the defualt return if the key isnt found in the dictionary.
        print(f"Default Value: {field.defaultValue}")
    if field.isNullable: # True or False
        print(f"Is Nullable: {field.isNullable}")
    if field.required: # True or False
        print(f"Is Required: {field.required}")&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 15:57:56 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-03-14T15:57:56Z</dc:date>
    <item>
      <title>Do the following python field checks exist?</title>
      <link>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267591#M67080</link>
      <description>&lt;P&gt;Looking for a python-way to check the existence of the following as part of a QA script:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If the correct default is assigned to a field;&lt;/LI&gt;&lt;LI&gt;If the field is nullable&lt;/LI&gt;&lt;LI&gt;If the field is required&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:21:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267591#M67080</guid>
      <dc:creator>ThomasColson</dc:creator>
      <dc:date>2023-03-14T15:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do the following python field checks exist?</title>
      <link>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267606#M67081</link>
      <description>&lt;P&gt;I would do something like this in Python but there might be better ways:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields_ls = arcpy.ListFields(input_layer)

for f in fields_ls:
    if f.defaultValue == 'whatever':
        pass
    else:
        print(f'The defualt value for {f.name} is not equal whatever')

    if f.isNullable:
        print(f.name, 'nullable')
    if f.required:
        print(f.name, 'req')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;you can access other attributes from the field object too:&lt;/P&gt;&lt;PRE&gt;f.aliasName&lt;BR /&gt;f.baseName&amp;nbsp;&lt;BR /&gt;f.editable&amp;nbsp;#bool&lt;BR /&gt;f.length&lt;BR /&gt;f.type&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Generally one good way to check the possible attributes/methods to use on an object in Python is to to pass it to the dir() like this:&lt;/P&gt;&lt;PRE&gt;dir(fields_ls[1])&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and it prints all those for you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;UPDATE: The way I did it was just to give you the idea how to access those info but was not scalable to check for default values of multiple fields. You should have a list or dictionary of default values to pass along. (The way @Anonymous User&amp;nbsp;suggested in the comments is great!)&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267606#M67081</guid>
      <dc:creator>Mahdi_Ch</dc:creator>
      <dc:date>2023-03-14T15:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Do the following python field checks exist?</title>
      <link>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267608#M67082</link>
      <description>&lt;P&gt;This should get you started.&amp;nbsp; Change out the defaults per field type in the dictionary.&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;import datetime
# Create a list of fields using the ListFields function
fields = arcpy.ListFields(in_Table)

defaultVal = {'Blob': 'stuff',
         'Date': datetime.datetime.now(),
         'Double': 54.2,
         'Geometry': 'Geometry',
         'GlobalID': 'Global ID',
         'Guid': 'Guid',
         'Integer': 23,
         'OID': 'Object ID',
         'Raster': 'Raster',
         'Single': 1,
         'SmallInteger': 3,
         'String': 'Text'}

# Iterate through the list of fields
for field in fields:
    # Not sure what Default value you are checking, but if they are different
    # for field types, you can set a dictionary and get it from there.
    
    print(f"Type: {field.type}")
    if field.defaultValue != defaultVal.get(field.defaultValue): # second param there is the defualt return if the key isnt found in the dictionary.
        print(f"Default Value: {field.defaultValue}")
    if field.isNullable: # True or False
        print(f"Is Nullable: {field.isNullable}")
    if field.required: # True or False
        print(f"Is Required: {field.required}")&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:57:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/do-the-following-python-field-checks-exist/m-p/1267608#M67082</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-03-14T15:57:56Z</dc:date>
    </item>
  </channel>
</rss>

