Chambers
-- -- --

Python - TypeError: 'NoneType' object is not iterable

Anonymous in /c/coding_help

270
I'm trying to create a "To-Don't App"<br> I'm having an issue with the `NoneType` object.<br><br>I'm trying to delete a item from list using index, but I'm still getting the `TypeError: 'NoneType' object is not iterable` error.<br>```python<br>class Lists:<br> def __init__(self):<br> self.todolists = []<br><br> def add_list(self):<br> toDoList = input("Enter the name of the list")<br> self.todolists.append(toDoList)<br><br><br> def print_lists(self):<br> for list in self.todolists:<br> print(list)<br><br> def item_delete(self, index):<br> del self.todolists[index]<br><br> def item_update(self, index, item):<br> self.todolists[index] = item<br><br> def item_list(self, name):<br> for index in range(len(self.todolists)):<br> if self.todolists[index] == name:<br> return index<br> return None<br><br><br>class Tods:<br> def __init__(self):<br> self.todomenu = ["Create New List", "Delete List", "Update List", "Add Item", "Delete Item", "Update Item" ]<br><br> def add_item(self, name):<br> item_name = input("Enter the name of the item")<br> item_count = input("Enter the count of the items")<br> item_detail = {<br> "name": item_name,<br> "count": item_count<br> }<br> self.todomenu.append(item_detail)<br><br><br> def print_tods(self):<br> for tod in self.todomenu:<br> print(tod)<br><br> def updatetod(self, index, item):<br> self.todomenu[index] = item<br><br> def deletetod(self, index):<br> del self.todomenu[index]<br><br> def item_list(self, name):<br> for index in range(len(self.todomenu)):<br> if self.todomenu[index] == name:<br> return index<br> return None<br><br><br><br>def main():<br> while True:<br> tod = Tods()<br> tods = Tods()<br><br> lists = Lists()<br> print("To-Don't App")<br> print("1.Create New List")<br> print("2 Delete List")<br> print("3.Update List")<br> print("4.Add Item")<br> print("5.Delete Item")<br> print("6.Update Item")<br> print("7.Print Lists")<br> print("8.Print Items")<br> a = int(input("Enter the number"))<br> if a == 1:<br> lists.add_list()<br> elif a == 6:<br> a = input("Enter the name of the list")<br> index = lists.item_list(a)<br> if index == None:<br> print("No list named that!")<br> else:<br> b = input("Enter the name of the item")<br> c = input("Enter the count of the item")<br> item_detail = {<br> "name": b,<br> "count": c<br> }<br> tods.updatetod(index, item_detail)<br> elif a == 2:<br> a = input("Enter the name of the list")<br> index = lists.item_list(a)<br> if index == None:<br> print("No list named that!")<br> else:<br> lists.item_delete(index)<br> elif a == 3:<br> a = input("Enter the name of the list")<br> index = lists.item_list(a)<br> if index == None:<br> print("No list named that!")<br> else:<br> b = input("Enter the name of the new list")<br> lists.item_update(index, b)<br> elif a == 4:<br> a = input("Enter the name of the list")<br> index = lists.item_list(a)<br> if index == None:<br> print("No list named that!")<br> else:<br> tods.add_item(a)<br> elif a == 5:<br> a = input("Enter the name of the list")<br> index = lists.item_list(a)<br> if index == None:<br> print("No list named that!")<br> else:<br> tods.deletetod(index)<br> elif a == 7:<br> lists.print_lists()<br> elif a == 8:<br> tods.print_tods()<br> else:<br> print("oops")<br><br>if __name__ == "__main__":<br> main()<br>```<br>I tried to make index to be `Integer` with `int()` function but it still gave me the same error.

Comments (6) 9822 👁️