How to reproduce this error in python:


Python methods will return NoneType if you expect a tuple from them and fail to return anything to fill them up:
>>> def baz():
...   print("k")
... 
>>> a, b = baz()
k
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
Assign NoneType to a variable, not allowed:
>>> a = NoneType
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'NoneType' is not defined
Try to iterate a NoneType in a for loop, that's a paddlin:
>>> for i in NoneType:
...   print("Yeah")
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'NoneType' is not defined
Try to concatenate None and a string, you better believe that's a paddlin:
>>> bar = "something"
>>> foo = None
>>> print foo + bar
TypeError: cannot concatenate 'str' and 'NoneType' objects
Try to use a variable passed in a method that contains NoneType:
>>> def foo(data):
...   print(data)
... 
>>> foo(NoneType)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'NoneType' is not defined

No comments:

Post a Comment