有一個考勤員工名單,每次增長刪除人員太麻煩,找python簡單寫一個腳本進行管理,python
01,實現人員追加操做ide
# 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,實現查詢刪除功能ip
#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')