1 #-*-coding:UTF-8 -*- 2 import datetime,time 3 import os 4 print u"=================尊敬的梦猩魂,欢迎使用记事本=================="; 5 con=True 6 while con: 7 k=int(raw_input("请您选择操作\n1.【写日志】\n2.【查看日志】\n3.【日志格式化】\n4.【备份日志】\n5.【日志恢复】\n6.【退出】".decode('utf-8').encode('gbk'))); 8 if (k==1): 9 times=r"d:\xinghun\\"+time.strftime("%Y-%m-%d",time.localtime()); 10 if os.path.exists(times)==False: 11 os.makedirs(times); 12 files=times+r"\mine.txt"; 13 o=open(files,"a+"); 14 content=raw_input("请输入您需要记录的事情: \n".decode('utf-8').encode('gbk')); 15 o.write(content); 16 o.close(); 17 print "======================================================"; 18 elif (k==2): 19 fls=raw_input("请输入日志分类名称: \n".decode('utf-8').encode('gbk')) 20 if os.path.exists(r"d:\xinghun\\"+fls+r"\mine.txt"): 21 print u"日志内容: \n"; 22 o=open(r"d:\xinghun\\"+fls+"mine.txt","a+"); 23 listcontent=o.readlines(); 24 for content in listcontent: 25 print content; 26 o.close(); 27 else: 28 print u"分类名称不存在!"; 29 print "======================================================"; 30 elif (k==3): 31 gsh=int(raw_input("您确定要格式化记事本吗?格式化后数据会全部消失\n确定输入1,取消输入2: \n".decode('utf-8').encode('gbk'))); 32 if(gsh==1): 33 fls=raw_input("请输入格式化日志分类名称: \n".decode('utf-8').encode('gbk')) 34 print u"日志正在格式化中......"; 35 if os.path.exists(r"d:\xinghun\\"+fls+"mine.txt"): 36 os.remove(r"d:\xinghun\\"+fls+"mine.txt"); 37 print u"记事本格式化成功!"; 38 open(r"d:\xinghun\\"+fls+"mine.txt","a+"); 39 else: 40 print u"记事本不存在!"; 41 print "======================================================"; 42 elif (k==4): 43 bf=int(raw_input("您确定要备份日志吗?\n确定输入1,取消输入2: \n".decode('utf-8').encode('gbk'))); 44 if (bf==1): 45 fls=raw_input("请输入备份日志的分类名称: \n".decode('utf-8').encode('gbk')) 46 print u"日志正在备份中......"; 47 if os.path.exists(r"d:\xinghun\\"+fls+"mine.txt"): 48 os.makedirs(r"d:\\xinghun\\"+fls+r"\\bf") 49 shutil.copyfile(r"d:\xinghun\\"+fls+r"\\mine.txt",r"d:\\xinghun\\"+fls+r"\\bf_mine.txt"); 50 shutil.move(r"d:\\xinghun\\"+fls+r"\\bf_mine.txt",r"d:\\xinghun\\"+fls+r"\\bf\\bf_mine.txt"); 51 print u"备份成功!"; 52 else: 53 print u"备份日志分类不存在!"; 54 elif (k==5): 55 hf=int(raw_input("您确定要回复日志吗?\n确定输入1,取消输入2: \n".decode('utf-8').encode('gbk'))); 56 if (hf==1): 57 print u"记事本正在恢复中......"; 58 shutil.copyfile(r"d:\\xinghun\\bf\\bf_mine.txt",r"d:\\xinghun\\mine.txt"); 59 else: 60 print u"欢迎下次使用!"; 61 con=False; 62
欢迎点击http://www.cnblogs.com/X-zone/梦猩魂的个人博客