```import pickle ,time ,os
def get_zhang(fname):
with open(fname,'rb') as f1:
lines=pickle.load(f1)
for line in lines:
print('%-12s%-8s%-8s%-12s%-20s' % tuple(line))
def shouru(fname):
riqi = time.strftime('%Y-%m-%d')
jine = int(input('请输入存入的金额'))
beizhu=input('请输入备注:')
with open(fname,'rb') as f1:
lines=pickle.load(f1)
yue=lines[-1][-2] + jine
jilu=[riqi,jine,0,yue,beizhu]
lines.append(jilu)
with open(fname,'wb') as f1:
pickle.dump(lines,f1)
def zhichu(fname):
riqi = time.strftime('%Y-%m-%d %H:%M:%S')
jine = int(input('请输入存入的金额'))
beizhu = input('请输入备注:')
with open(fname, 'rb') as f1:
lines = pickle.load(f1)
print(type(lines))
exit()
yue = lines[-1][-2] - jine
jilu = [riqi, jine,yue,0, beizhu]
lines.append(jilu)
with open(fname, 'wb') as f1:
pickle.dump(lines, f1)
def show_menu():
fname='jizhang.data'
line1 = [['2020-1-31', 0, 0, 10000, 'init data']]
if not os.path.exists(fname):
with open(fname,'wb') as f1:
pickle.dump(line1,f1)
cmds={'3':get_zhang,'1':shouru,'2':zhichu}
prompt='''
0) 退出
1)收入
2)支出
3)查询
请选择(0/1/2/3):'''
while 1:
choice=input(prompt).strip()
if choice not in ['0','1','2','3']:
print('无效的输入,请重新输入')
if choice=='0':
print('bye-bye')
break
cmds[choice](fname)
if __name__ == '__main__':
show_menu()
python-记账脚本
猜你喜欢
转载自blog.csdn.net/weixin_45942735/article/details/104132522
今日推荐
周排行