def file_read():
with open('D:\pytharm\jichuyufa\day2\shop.txt', 'r', encoding='utf8') as f:
for i1 in f.readlines():
li1 = i1.split(',')
print(li1)
return li1
def file_wi():
with open('D:\pytharm\jichuyufa\day2\shop.txt', 'a+', encoding='utf8') as f:
f.write(',袜子')
li = file_read()
flag = True
while flag:
print('-------------------列表-------------------------')
for i in range(len(li)):
print('商品序号: {} - 商品名称: {}'.format(i+1,li[i]))
print('-------------------添加商品输入T或者t-------------------------')
print('-------------------显示商品输入x或者X-------------------------')
xu_ze = input('请输入您的选择')
if xu_ze.lower() == 'x':
xu_hao = input('请输入商品序号')
if xu_hao.isdigit():
xu_hao1 = int(xu_hao)
if xu_hao1 < len(li)+1:
ming_ch = li[xu_hao1-1]
print('选择的商品的 %s' % ming_ch)
else:
print('不在列表范围内')
elif xu_ze.lower() == 'q':
print('---------------------', xu_ze)
flag = False
elif xu_ze.lower() == 't':
name = input('输入商品名称')
li.append(name)
file_wi()