TypeError: 'NoneType' object is not iterable

3336
1
Jump to solution
03-04-2021 04:10 AM
CliveSwan
Occasional Contributor II

Greetings,

I want to search all Features, but exclude those that are a 'NoneType' object

I tried to exclude the 'NoneType' object in the search, this is not working??

Appreciate any pointers, to skip the 'NoneType'

 

serviceItems = portal.content.search("*",  item_type="Feature*", max_items=4000)
for item in serviceItems:
   if item != 'NoneType':
		   layers = item.layers
		   #print(layers)
			#try:
			for lyr in item.layers:
				print(item.id, item.url, lyr.properties["id"], lyr.properties["name"], item.tags )
				rowitem = (item.id, item.url, lyr.properties["id"], lyr.properties["name"], item.tags)
				filewriter.writerow(rowitem )
	else:
		print("EROR")

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor
if item is not None:
    blah blah
# or
if item:
    blah blah

the type is None, you don't test for Nonetype


... sort of retired...

View solution in original post

1 Reply
DanPatterson
MVP Esteemed Contributor
if item is not None:
    blah blah
# or
if item:
    blah blah

the type is None, you don't test for Nonetype


... sort of retired...