<?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 Change text values to NULL using update cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147345#M63859</link>
    <description>&lt;P&gt;I am trying to write a script that will take different permutations of the word Null and convert them to true database Nulls. I have users populate 'Null', 'NULL' or similar, and I need to convert these to true Nulls.&lt;/P&gt;&lt;P&gt;I have a list of the different permutations and a geodatabase with several feature classes. I'm trying to loop through my list and compare against all string values in all feature class. If there is a match, convert the string to the true Null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an invalid syntax error on line 26:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;row = [None if i in nullList else pass for i in row]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I replace pass with print ('Test') it changes every value to Null. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import time

inputGDB = r'C:\Test_null.gdb'

# Set workspace to input GDB
arcpy.env.workspace = inputGDB

nullList = ['', ' ', '  ', '   ', '-', '--', '---', '&amp;lt;Null&amp;gt;', '&amp;lt;NULL&amp;gt;', 'Null', 'NULL', '”Null”', '”NULL”']

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

# Loop through all feature classes
print('Reading Feature Classes...')
for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        # Build a list of all TEXT/String Fields where NULL values are allowed
        fieldList = [i.name for i in arcpy.ListFields(fc) if i.type == 'String' and i.isNullable is True]

        # Iterate through each row and execute the clean
        with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
            for row in cursor:
                row = [None if i in nullList else pass for i in row]
                cursor.updateRow(row)

print('Done.')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Mar 2024 23:23:07 GMT</pubDate>
    <dc:creator>tigerwoulds</dc:creator>
    <dc:date>2024-03-03T23:23:07Z</dc:date>
    <item>
      <title>Change text values to NULL using update cursor</title>
      <link>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147345#M63859</link>
      <description>&lt;P&gt;I am trying to write a script that will take different permutations of the word Null and convert them to true database Nulls. I have users populate 'Null', 'NULL' or similar, and I need to convert these to true Nulls.&lt;/P&gt;&lt;P&gt;I have a list of the different permutations and a geodatabase with several feature classes. I'm trying to loop through my list and compare against all string values in all feature class. If there is a match, convert the string to the true Null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an invalid syntax error on line 26:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;row = [None if i in nullList else pass for i in row]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I replace pass with print ('Test') it changes every value to Null. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import time

inputGDB = r'C:\Test_null.gdb'

# Set workspace to input GDB
arcpy.env.workspace = inputGDB

nullList = ['', ' ', '  ', '   ', '-', '--', '---', '&amp;lt;Null&amp;gt;', '&amp;lt;NULL&amp;gt;', 'Null', 'NULL', '”Null”', '”NULL”']

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []

# Loop through all feature classes
print('Reading Feature Classes...')
for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        # Build a list of all TEXT/String Fields where NULL values are allowed
        fieldList = [i.name for i in arcpy.ListFields(fc) if i.type == 'String' and i.isNullable is True]

        # Iterate through each row and execute the clean
        with arcpy.da.UpdateCursor(fc, fieldList) as cursor:
            for row in cursor:
                row = [None if i in nullList else pass for i in row]
                cursor.updateRow(row)

print('Done.')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Mar 2024 23:23:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147345#M63859</guid>
      <dc:creator>tigerwoulds</dc:creator>
      <dc:date>2024-03-03T23:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Change text values to NULL using update cursor</title>
      <link>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147351#M63861</link>
      <description>&lt;LI-CODE lang="python"&gt;row = ['', 'a', ' ', '  ', '   ', '-', '--', '---', '&amp;lt;Null&amp;gt;', '&amp;lt;NULL&amp;gt;', 'Null', 'NULL', '”Null”', '”NULL”']

nullList = ['', ' ', '  ', '   ', '-', '--', '---', '&amp;lt;Null&amp;gt;', '&amp;lt;NULL&amp;gt;', 'Null', 'NULL', '”Null”', '”NULL”']

[None if i in nullList else pass for i in row]
  File "&amp;lt;ipython-input-7-9b1bf3f7cd3e&amp;gt;", line 1
    [None if i in nullList else pass for i in row]
                                   ^
SyntaxError: invalid syntax

# -- no pass

[None if i in nullList else i for i in row]

[None,
 'a',
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None,
 None]&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 24 Feb 2022 00:30:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147351#M63861</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-24T00:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Change text values to NULL using update cursor</title>
      <link>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147356#M63862</link>
      <description>&lt;P&gt;Thanks! Replacing pass with i did the trick.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 01:03:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-text-values-to-null-using-update-cursor/m-p/1147356#M63862</guid>
      <dc:creator>tigerwoulds</dc:creator>
      <dc:date>2022-02-24T01:03:27Z</dc:date>
    </item>
  </channel>
</rss>

