Python-w2

此页面是否是列表页或首页?未找到合适正文内容。

Python-w2

标签:python-w2

一个购物车实例,大量的列表,字典,文件互相写入,读取操作。

对于嵌套字典的取值,比较繁琐。

该程序功能较为单一,代码了较大,没有使用函数,有很多地方可以改进。

#!/usr/bin/env python# -*- coding: utf-8 -*-import os,sys,time# init menu prod list_prod_list = []# init a shopping cart_shopping_his = []_shopping_cart = []# init user info list_user = {}# load prod listif not os.path.exists(\”w2_prod.txt\”):open(\”w2_prod.txt\”, \”w\”).close()else:with open(\”w2_prod.txt\”,\”r\”) as prod_list:lines = prod_list.readlines()if lines:print(\”Load prod list…\”)for line in lines:_prod_list.append(line.strip())else:print(\”Nothing in prod list. Please import production with the format: prod_name,prod_price\”)exit()# create user list and buy listif not os.path.exists(\”w2_user.txt\”):open(\”w2_user.txt\”,\”w\”).close()if not os.path.exists(\”w2_buy.txt\”):open(\”w2_buy.txt\”,\”w\”).close()# init user infowith open(\”w2_user.txt\”,\”r+\”) as names:lines = names.readlines()if lines:print(\”Load user information…\”)for i in range(len(lines)):_user[str(i)] = {}(_id,_uname,_upwd,_ustate,_ubalance) = lines[i].strip().split(\”,\”,5)

作者: 鲁大师

为您推荐

返回顶部