'How to iterate through instance of a parent class?
I'm trying to iterate through a dictionary object initialized in a parent class, and append it to an instance in a child class. However, when I try to iterate through it, I receive...
TypeError: 'NoneType' object is not iterable
...when running for key in self.inv
class Inventory:
'''Create inventory class'''
def __init__(self, inv):
self.inv = inv
class Cart(Inventory):
'''Customer shopping cart class'''
def __init__(self, cart):
self.cart = cart
self.inv = super(Inventory).__init__()
def scanning(self, inv):
Inventory.displayInv(inv)
print(vars(inv))
scanned = 0
while scanned != "pay":
scanned = input("Input a barcode to scan or type 'pay' to pay: ")
if scanned.isdigit():
scanned = int(scanned)
for key in self.inv: #THIS IS WHERE THE ERROR OCCURS
if key == scanned:
print(self.inv[key])
Cart.updateCart(self.cart, self.inv, key)
total_price, total_items = Cart.updateTotals(self)
Cart.displayCart(self, total_items, total_price)
break
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
