1 # -*- coding:utf-8 -*-
2 # author: heimu
3
4 import os,sys
5 import json
6
7 user_dic = {} # 保存账户信息
8 shopping_list = {} # 保存账户购物清单
9 salary_list = {} # 保存账户余额
10
11 goods = [
12 {"name": "电脑", "price": 1999},
13 {"name": "鼠标", "price": 10},
14 {"name": "游艇", "price": 20},
15 {"name": "美女", "price": 998},
16 ]
17
18 def init_all():
19 '''
20 初始化 user_dic, shopping_list, salary_list
21 :return:
22 '''
23 user_dic['heimu_1'] = '111111'
24 user_dic['heimu_2'] = '222222'
25 user_dic['heimu_3'] = '333333'
26 for key in user_dic.keys():
27 shopping_list[key] = []
28 salary_list[key] = 0
29 save_data() # 保存初始化的数据到本地文件
30
31 def save_data():
32 '''
33 保存数据到本地文件
34 :return:
35 '''
36 with open("user_dic.txt",'w') as f:
37 json.dump(user_dic,f)
38 with open("shopping_list.txt",'w') as f:
39 json.dump(shopping_list,f)
40 with open("salary_list.txt",'w') as f:
41 json.dump(salary_list,f)
42
43 def download_data():
44 '''
45 从本地文件下载数据
46 :return:
47 '''
48 with open("user_dic.txt",'r') as f:
49 user_dic = json.load(f)
50 with open("shopping_list.txt",'r') as f:
51 shopping_list = json.load(f)
52 with open("salary_list.txt",'r') as f:
53 salary_list = json.load(f)
54 return user_dic,shopping_list,salary_list
55
56 def inquire_salary():
57 '''
58 账户查询余额,高亮打印账户余额
59 :return:
60 '''
61 print('