码迷,mamicode.com
首页 > 编程语言 > 详细

Python日记本

时间:2014-05-25 08:46:15      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

bubuko.com,布布扣
 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     
bubuko.com,布布扣

 

Python日记本,布布扣,bubuko.com

Python日记本

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/X-zone/p/3750691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!