本文实例为大家分享了python超市商品销售管理系统的具体代码,供大家参考,具体内容如下
class Goods(object):
def __init__(self, id, name, price):
self.id = id
self.name = name
self.price = price
def __str__(self):
info = "编号:%s\t商品名称:%s\t\t价格:%d" % (self.id, self.name, self.price)
return info
class ShopManager(object):
def __init__(self, path):
# path:表示读取文件的路径 shopdic:表示存放内存的容器
self.path = path
self.shopdic = self.readFileToDic()
def readFileToDic(self):
# 读取文件,写入到字典中
f = open(self.path, 'r', encoding='utf-8')
clist = f.readlines()
f.close()
index = 0
shopdic = {}
while index < len(clist):
# 将每一行的字符串进行分割,存放到新的列表中
ctlist = clist[index].replace('\n', "").split("|&