有一个考勤员工名单,每次增加删除人员太麻烦,找python简单写一个脚本进行管理,
01,实现人员追加操作
# add amd delete card #coding=utf-8 wfile=open(‘account.dat‘) readfile=wfile.read() print "请输入新社员信息。" print "社员信息如:C07004,dddd,于欣,2,020353,,,,,,,,,," print "C07004:社员编号" print "dddd:公司简称" print "于欣:社员姓名" print "2:所属于部门" print "020353,考勤卡号" print "一定要跟10个,,,,,,,,,," infile=raw_input(‘请输入新社员:‘) out=open(‘account.dat‘,‘w‘) out.write(readfile+‘\n‘) #out.write("\n") out.writelines([infile.strip()]) out.close()
02,实现查询删除功能
#delete card #coding=utf-8 import shutil dela = raw_input(‘请输入已离职工:‘) with open(‘account.dat‘, ‘r‘) as f: with open(‘test.txt.new‘, ‘w‘) as g: for line in f.readlines(): if dela not in line: g.write(line) shutil.move(‘test.txt.new‘, ‘account.dat‘)
原文地址:http://xjlsky.blog.51cto.com/22754/1766129