Мой код отлично работает в Pycharm, но я получаю сообщение об ошибке, если набираю add в консоли (Ubuntu Terminal).
Ошибка, которую я получаю в консоли за пределами Pycharm IDE:
Traceback (most recent call last):
File "main.py", line 37, in <module>
getStr = input('>: ')
File "<string>", line 1, in <module>
NameError: name 'add' is not defined
Мой код:
#!/user/bin/python3
class Item:
itemsCount = 0
def __init__(self, sku, bWidth, bHeight, bLength, quantity, bWeight):
self.sku = sku
self.bWidth = bWidth
self.bHeight = bHeight
self.bLength = bLength
self.quantity = quantity
self.bWeight = bWeight
Item.itemsCount += 1
def DisplayItem(self):
print('[SKU : ', self.sku, '] [Width : ', self.bWidth, '] [Height : ', self.bHeight,
'] [bLength : ', self.bLength, '] [Quantity : ', self.quantity, '] [bWeight : ',
self.bWeight, ']')
items = [Item]
print('Dan\'s Warehouse Inventory')
print('Current Stock in inventory : [', Item.itemsCount,']\n' )
while True:
getStr = input('>: ')
if getStr == 'add':
getSku = input('SKU : ')
getWidth = int(input('Width : '))
getHeight = int(input('Height : '))
getLength = int(input('bLength : '))
getQuantity = int(input('Quantity : '))
getWeight = int(input('Weight : '))
items.append(Item(getSku, getWidth, getHeight, getLength, getQuantity, getWeight))
print(Item.itemsCount)
else:
print('Invalid command.')
Я не уверен, что делаю неправильно ..Любая помощь приветствуется!