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:
- It is recommended that you expose your arguments within the function call. Don't
def nbhs_1(triple)
, do insteaddef nbhs_1(X, Y, Z)
. In this way you can actually have one single function that does what you want (easier to maintain) - Return your result. At the moment you are printing the outcome of the function call but you are not returning those results.
- I'm also not sure the
canonicalize_radical()
call is also done properly. Python is object-oriented and by writingvar.canonicalize_radical()
you are inferring thatvar
should itself know about this function (e.g. the function is part of var) but that sounds wrong. The correct call may becanonicalize_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
Concatenate a Numpy Array to Another Numpy Array
Catching Stdout in Realtime from Subprocess
How to Index into a Dictionary
Pandas Dataframe Stored List as String: How to Convert Back to List
Python: Defining My Own Operators
How to Build a Numpy Array from a Generator
Emulating Bash 'Source' in Python
Python3: Importerror: No Module Named '_Ctypes' When Using Value from Module Multiprocessing
Loop That Also Accesses Previous and Next Values
How to Get My Program to Sleep for 50 Milliseconds
Save List of Dataframes to Multisheet Excel Spreadsheet
Python Socket Receive Large Amount of Data
How to Read the Rgb Value of a Given Pixel in Python
Extract Images from PDF Without Resampling, in Python