<?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: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1087152#M61990</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/22623"&gt;@RPGIS&lt;/a&gt;&amp;nbsp;; way to stick with it!&lt;/P&gt;</description>
    <pubDate>Mon, 09 Aug 2021 15:52:01 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-08-09T15:52:01Z</dc:date>
    <item>
      <title>Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086123#M61950</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;So I am having an issue where every time I try to create a list, either using a comprehension or other, that returns the error of either 'NoneType' is not subcriptable or iterable. I have tried multiple methods to bypass this error, but it seems that this error persists somewhere and I can't figure out where.&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;#Get Field Indexes
OIN = SelectedTempFields.index('ORIG_FID')
VIN = SelectedTempFields.index('ValveID')
DIN = SelectedTempFields.index('LAND_DIST')
LIN = SelectedTempFields.index('LAND_LOT_1')

#Create Dictionary Of Specific Values
CreatedTempList = {}

#Gather Created Temporary Polygon Layer Values
for DLL in DistrictsAndLandLots:
        District = DLL[0]
        Landlot = DLL[1]
        
        DistText = str(District).zfill(2)
        LandText = str(Landlot).zfill(4)
        DistLandText = DistText + LandText

 
        values = [row[VIN][-3:] for row in arcpy.da.SearchCursor(CreatedTemp, SelectedTempFields) if row[DIN] == District and row[LIN] == Landlot and row[VIN][-1] is int()]
        if values:
                print (sorted(set(values)))
                CreatedTempList[DistLandText] = max(values)

for key, values in CreatedTempList.items():
        print (key, ': ', values)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-center"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;small snippet of the code&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I also seem to be getting two error codes simultaneously, which is a bit odd, and I am not sure exactly how this error is occurring.&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;Traceback (most recent call last):
  File "U:\Models_Tools\Scripts for Water and Sewer Database\Update Valve ID Field.py", line 101, in &amp;lt;module&amp;gt;
    values = [row[VIN][-3:] for row in arcpy.da.SearchCursor(CreatedTemp, SelectedTempFields) if row[DIN] == District and row[LIN] == Landlot and row[VIN][-1] is int()]
  File "U:\Models_Tools\Scripts for Water and Sewer Database\Update Valve ID Field.py", line 101, in &amp;lt;listcomp&amp;gt;
    values = [row[VIN][-3:] for row in arcpy.da.SearchCursor(CreatedTemp, SelectedTempFields) if row[DIN] == District and row[LIN] == Landlot and row[VIN][-1] is int()]
TypeError: 'NoneType' object is not subscriptable&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on this would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 13:15:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086123#M61950</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-05T13:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086198#M61952</link>
      <description>&lt;P&gt;What have you tried?&amp;nbsp; How are trapping for Null/None values and what are you doing with them?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 15:42:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086198#M61952</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-08-05T15:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086208#M61953</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;So here are the things that I have tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Isolating each variable to determine if the result returns a 'NoneType' value&lt;/LI&gt;&lt;LI&gt;Checking to determine object type (type(values))&lt;/LI&gt;&lt;LI&gt;Checking if the list is a list by using bool(values)&lt;/LI&gt;&lt;LI&gt;Checking if the len(values) is &amp;gt; 0&lt;/LI&gt;&lt;LI&gt;Try and\or Except statements to raise the error (had little to no success with this option)&lt;/LI&gt;&lt;LI&gt;Checking other list for 'NoneType' values&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;After all of these attempts to find the issue; I still couldn't determine where the issue is.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 15:55:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086208#M61953</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-05T15:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086225#M61955</link>
      <description>&lt;P&gt;I was hoping to see the actual code you used.&lt;/P&gt;&lt;P&gt;Your select statement in the search cursor is pretty complex but I &amp;nbsp;&lt;EM&gt;think&lt;/EM&gt; if you use a series of if/elif statements that check for null values in each of your indices followed with a pass ( or a print statement saying Such and Such index is null) you &lt;EM&gt;should&lt;/EM&gt; be able to avoid the error.&amp;nbsp; Emphasis in &lt;EM&gt;&lt;STRONG&gt;think&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;should.&lt;/STRONG&gt;&lt;/EM&gt;..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;OIN = SelectedTempFields.index('ORIG_FID')
VIN = SelectedTempFields.index('ValveID')
DIN = SelectedTempFields.index('LAND_DIST')
LIN = SelectedTempFields.index('LAND_LOT_1')

#blah blah blah...
if OIN is None:
    pass
elif VIN is None:
    pass
elif DIN is None:
    pass
elif LIN is None:
   pass
else:
   # do your list comprehension with the search cursor....&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 16:18:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086225#M61955</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-08-05T16:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086279#M61957</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3374"&gt;@JoeBorgione&lt;/a&gt;&amp;nbsp;for the advice. I will give this a try and let you know how this goes. I didn't show the entire code since I was concerned with file locations of the data but I didn't think to just post it and delete the file locations. In any case, here is the complete script. It has been changed since I discovered another solution that provided the same information without needing any additional layers.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import time
import os

print ('Process Start Time '+ time.strftime('%I:%M:%S:%p'))

arcpy.env.OverwriteWorkspace = True

#Set District and LandLot Layer Input Parameter
#District_LandLot_fc = arcpy.GetParameterAsText(0)
District_LandLot_fc = polygonfc
DistrictLandLot_TempLayer = arcpy.MakeFeatureLayer_management(District_LandLot_fc, r"in_memory\DistrictLandLot_TempLayer")

#Loop Through Temporary District and LandLot Layer To Get Field Names
print ("Acquiring District and LandLot Values At " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Acquiring District and LandLot Values At {}".format(time.strftime('%I:%M:%S:%p')))

DistrictLandLots_Fields = ['LAND_DIST', 'LAND_LOT']
DistrictLandLot_fields = []

allfields = arcpy.ListFields(DistrictLandLot_TempLayer)
for field in allfields:
        if field.name in DistrictLandLots_Fields:
                DistrictLandLot_fields.append(field.name)

DistrictsAndLandLots = []

with arcpy.da.SearchCursor(DistrictLandLot_TempLayer, DistrictLandLot_fields) as lcur:
        for row in lcur:
                DistrictsAndLandLots.append(row)

print ("Acquired District and LandLot Values At " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Acquired District and LandLot Values At {}".format(time.strftime('%I:%M:%S:%p')))

#Make lists of the important fields that coincide both layers
mainfields = ['OBJECTID',
              'ValveID',
              'LAND_DIST',
              'District',
              'Land_Lot',
              'LAND_LOT',
              'LAND_LOT_1',
              'Comments_Operational',
              'ORIG_FID',
              'Join_Count'
              ]

#Set Feature Class and Workspace Input Parameter
#FeatureClass = arcpy.GetParameterAsText(1)
FeatureClass = pointfc
workspace = os.path.split(FeatureClass)[0]
if workspace.split('.')[-1] != '.gdb' or workspace.split('.')[-1] != '.sde' or workspace.split('.')[-1] != '.shp' :
        workspace = os.path.split(workspace)[0]

#Get Feature Class Geometry Type
##geometryType = arcpy.Describe(FeatureClass).shapeType
print ("Acquiring All Update Values From Temporary Polygon Layer At " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Acquiring All Update Values From Temporary Polygon Layer At {}".format(time.strftime('%I:%M:%S:%p')))

#Create Temporary Point Layers
TempPointFeature = arcpy.FeatureToPoint_management(FeatureClass, r'in_memory\TempPointFeature')
TempPointFeatureLayer = arcpy.MakeFeatureLayer_management(TempPointFeature, r'in_memory\TempPointFeatureLayer')

#Create Temporary District and Landlot Layer For Collecting Values
CreatedTemp = arcpy.analysis.TabulateIntersection(DistrictLandLot_TempLayer, DistrictLandLot_fields, TempPointFeatureLayer, r'in_memory\OutTable', ['ValveID'])

#Get Fields From Temporary Polygon Layer
SelectedTempFields = []
allfields = arcpy.ListFields(CreatedTemp)
for field in allfields:
        if field.name in mainfields:
                #print (field.name)
                SelectedTempFields.append(field.name)

#Create Dictionary Of Specific Values
CreatedTempList = {}
        
#Get Field Indexes
VIN = SelectedTempFields.index('ValveID')
DIN = SelectedTempFields.index('LAND_DIST')
LIN = SelectedTempFields.index('LAND_LOT')

#Gather Created Temporary Polygon Layer Values
for DLL in DistrictsAndLandLots:
        District = DLL[0]
        Landlot = DLL[1]

        DistText = str(District).zfill(2)
        LandText = str(Landlot).zfill(4)
        DistLandText = DistText + LandText
 
        values = [row[VIN][-3:] for row in arcpy.da.SearchCursor(CreatedTemp, SelectedTempFields) if row[DIN] == District and row[LIN] == Landlot and str(row[VIN][-1]).isnumeric()]
        if len(values) &amp;gt; 0:
                print (values)

for key, values in CreatedTempList.items():
        print (key, ': ', values)
                        
print ("Acquired All Update Values From Temporary Polygon Feature Layer " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Acquired All Update Values From Temporary Polygon Feature Layer At {}".format(time.strftime('%I:%M:%S:%p')))
        
#Get Queried Values From Layer
NewTempPointFeatureLayer = arcpy.MakeFeatureLayer_management(TempPointFeature, r'in_memory\NewTempPointFeatureLayer', arcpy.GetParameterAsText(2))

#Get Fields For Spatial Join Temporary Layer
SpatialJoinfields = []
allfields = arcpy.ListFields(temp_SpatialJoinPoint)
for field in allfields:
        if field.name in mainfields:
                print (field.name)
                SpatialJoinfields.append(field.name)
                
#Set Dictionaries
VIDChanges = {}

#Get Field Indexes
OID = SpatialJoinfields.index('ORIG_FID')
VIN = SpatialJoinfields.index('ValveID')
DIN = SpatialJoinfields.index('LAND_DIST')
LIN = SpatialJoinfields.index('LAND_LOT_1')
CO = SpatialJoinfields.index('Comments_Operational')

for value in CreatedTempList:
        i = 0
        value_list = []
        with arcpy.da.SearchCursor(temp_SpatialJoinPoint, SpatialJoinfields) as cursor:
                for row in cursor:
                        #print (row)
                        if row[VIN] not in CreatedTempList:
                                print (row)
                                
                                        
#Loop Through Featureclasses in Local Database
print ("Updating Feature Class At " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Updating Feature Class At {}".format(time.strftime('%I:%M:%S:%p')))

#Start editing operation
##edit = arcpy.da.Editor(workspace)
##edit.startEditing(False, True)
##edit.startOperation()

#Start Updating Feature Class
fields = []
allfields = arcpy.ListFields(FeatureClass)
for field in allfields:
        if field.name in mainfields:
                fields.append(field.name)

OID = fields.index('OBJECTID')
VIN = fields.index('ValveID')
DIN = fields.index('District')
LIN = fields.index('Land_Lot')

with arcpy.da.SearchCursor(FeatureClass, fields) as cursor:
#with arcpy.da.UpdateCursor(FeatureClass, fields) as cursor:
        for row in cursor:
                for key,values in VIDChanges.items():
                        if row[OID] == key:
                                row[DIN] = values[0]
                                row[LIN] = values[1]
                                row[VIN] = values[2]
                                #cursor.updateRow(row)
                                
print ("Completed Updating Feature Class At " + time.strftime('%I:%M:%S:%p'))
arcpy.AddMessage("Completed Updating Feature Class At {}".format(time.strftime('%I:%M:%S:%p')))

#End Editing Session
##edit.stopOperation()
##edit.stopEditing(True)

#Delete all in memory files
arcpy.Delete_management(DistrictLandLot_TempLayer)
arcpy.Delete_management(temp_SpatialJoinPoint)
arcpy.Delete_management(TempPointFeature)
arcpy.Delete_management(TempPointFeatureLayer)
arcpy.Delete_management(CreatedTemp)
arcpy.Delete_management(NewTempPointFeatureLayer)

print ('Process End Time '+ time.strftime('%I:%M:%S:%p'))&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 Aug 2021 17:52:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086279#M61957</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-05T17:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086282#M61958</link>
      <description>&lt;P&gt;So this works for you without errors?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 18:02:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086282#M61958</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-08-05T18:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086312#M61959</link>
      <description>&lt;P&gt;So I ran a few tests and tried a few modifications, but the issue for some reason is still persisting despite your suggestions. I have never encountered an issue like this before so troubleshooting it is dodgy at best.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 19:19:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1086312#M61959</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-05T19:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1087150#M61989</link>
      <description>&lt;P&gt;So I figured out the issue to my conundrum and here is what I came up with:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;DistrictsLandLots = [[values[0], values[1], values[2]] for values in arcpy.da.SearchCursor(CreatedTemp, SelectedTempFields) if None not in values]&lt;/LI-CODE&gt;&lt;P&gt;So there was a value of None that was causing the issue. I couldn't figure out previously on how to isolate it until recently and wrote the script as such in order to overlook that value.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 15:50:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1087150#M61989</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-09T15:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1087152#M61990</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/22623"&gt;@RPGIS&lt;/a&gt;&amp;nbsp;; way to stick with it!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 15:52:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1087152#M61990</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-08-09T15:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Having an issue where the 'NoneType' object error is either not subscriptable or iterable when using list comprehension or list in general?</title>
      <link>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1092584#M62181</link>
      <description>&lt;P&gt;The error is self-explanatory. You are trying to index None. You can not, because 'NoneType' object is &lt;A href="http://net-informations.com/python/err/nonetype.htm" target="_self"&gt;not subscriptable&lt;/A&gt;. This means that you tried to do:&lt;/P&gt;&lt;P&gt;None[something]&lt;/P&gt;&lt;P&gt;In general, the error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 06:57:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-an-issue-where-the-nonetype-object-error-is/m-p/1092584#M62181</guid>
      <dc:creator>leneborma</dc:creator>
      <dc:date>2021-08-26T06:57:19Z</dc:date>
    </item>
  </channel>
</rss>

