Typeerror: 'Nonetype' Object Is Not Iterable in Python

TypeError: 'NoneType' object is not iterable in Python

It means the value of data is None.

TypeError: NoneType object is not iterable

There are two things wrong with your code:

  • First you are not returning next_heights in your function
def nextYear(heights):
next_heights = []
for i in range(len(heights)):
next_heights.append(heights[i] + 5)
i += 1
return next_heights

Without the return line, it will return None and pass it to printList function, also you do not need to print inside nextYear as you already calling printList to print after the function returns the highlights

  • Second thing is increasing the iterator, you literally cannot do that, you could try this little example to understand what I mean
for i in range(10):
print(i)
i +=15555

So first thing to do is to remove this line from your loop

def nextYear(heights):
next_heights = []
for i in range(len(heights)):
next_heights.append(heights[i] + 5)
return next_heights

It will be incremented automatically every iteration, if you want it to be increased by two instead of one then you can specify that in range() function as a step size.

How to fix TypeError: 'NoneType' object is not iterable

None denotes that nothing was found, you might use if ... is None check rather than try-except to skip if nothing was found as follows

for occupation in occupations_list:
offers_page = requests.get(occupation)
offers_soup = BeautifulSoup(offers_page.content, 'lxml')
offers = offers_soup.find('ul', class_='result-list list-unstyled')
if offers is None:
continue
print("Processing offers")

replace print("Processing offers") with your actual processing

NoneType' object is not iterable - where is an error?

The main problem is that you are not structuring the function properly:

  1. It is recommended that you expose your arguments within the function call. Don't def nbhs_1(triple), do instead def nbhs_1(X, Y, Z). In this way you can actually have one single function that does what you want (easier to maintain)
  2. Return your result. At the moment you are printing the outcome of the function call but you are not returning those results.
  3. I'm also not sure the canonicalize_radical() call is also done properly. Python is object-oriented and by writing var.canonicalize_radical() you are inferring that var should itself know about this function (e.g. the function is part of var) but that sounds wrong. The correct call may be canonicalize_radical(var)

Basically, this should be closer to a correct solution:

A=1*sqrt(6)
B=4*sqrt(3)
C=9*sqrt(2)

def nbhs(X, Y, Z):
out1 = canonicalize_radical(X)
out2 = canonicalize_radical(X*Y-Z)
out3 = canonicalize_radical(Y)
return out1, out2, out3

l = [max(nbhs(A, B, C)), max(nbhs(B, A, C)), max(nbhs(C, B, A))]

TypeError: argument of type 'NoneType' is not iterable in on_message

Since you're using on_message and since it does have a topic this suggests that the channel can only be a TextChannel.

This doesn't really matter but the channel that you're sending a message in doesn't have a set topic and so it will return None. You could solve this by adding a quick if statement eg.

@client.event
async def on_message(message):
if "S|Wave" in message.channel.topic if message.channel.topic else "":
await message.add_reaction("quot;)

How to handle 'NoneType' object is not iterable

The problem is here:

from itertools import combinations

def combinations(items):
...

Your combinations function masks the combinations you import from itertools, so you're just calling your own function, which implicitly returns None. Just rename your function to something else and you'll be able to reference the desired imported function.



Related Topics



Leave a reply



Submit