logfunction.py:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import os
import time
def quit():
sys.exit(0)
def writelog():
name = time.strftime('%Y-%m-%d',time.localtime(time.time()))
try:
fd = open(name, 'w')
except IOError:
print u'文件不存在啊...'
endio = True
print u"输入日记:"
while endio:
line = raw_input()
if line == 'end':
break
fd.write(line + '\n')
fd.close()
def readlog():
print u'输入日记名:'
name = raw_input()
try:
fd = open(name, 'r')
except IOError:
print u'文件不存在啊...'
lines = fd.readlines()
for line in lines:
print line
fd.close()
log.py:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from logfunction import *
FuntionAct = {'w':writelog, 'r':readlog, 'q':quit}
end = True
while end:
print u'写日记(w)'
print u'读日记(r)'
print u'退出(q)'
choice = raw_input('输入操作:')
FuntionAct[choice]()