所以我修复了以前没有正确定义列表的问题。是否可以组织列表中的项目?或者它总是会显示它的添加方式?如果有一种方法可以在创建并添加后更新列表,怎么做?
这是主类文件:
def storing():
the_item = Ch10b_retailItemClass.RetailItem("","","")
for count in range(3):
desc = input('What item would you like to inventory?\n')
unit = input('How many of them are in stock?\n')
price = input('What\'s the price for this item?\n')
the_item.set__desc(desc)
the_item.set__unit(unit)
the_item.set__price(price)
# I want to print the list as a whole.
print(the_item.list_function())
这是我的班级导入:
class RetailItem:
global inv
inv = []
# init function, getting us started and initializing variables?
def __init__(self, desc, unit, price):
self.__desc = desc
self.__unit = unit
self.__price = price
# functions that create temp place holders
def set__desc(self, desc):
self.__desc = desc
inv.append(desc)
def set__unit(self, unit):
self.__unit = unit
inv.append(unit)
def set__price(self, price):
self.__price = price
inv.append(price)
def list_function(self):
return inv