Python 示例 饮水记录

因为每天都需要喝水  这是非常重要的 

目录结构:

      

├─bin
│ │ start.py
│ │
│ └─__pycache__
│ start.cpython-36.pyc

├─core
│ │ src.py
│ │
│ └─__pycache__
│ src.cpython-36.pyc

└─log
access.log

 

 

 

代码内容:

start.py

 1 """
 2 Description:
 3 Author:Nod
 4 Date:
 5 Record:
 6 #---------------------------------v1-----------------------------------#
 7 """
 8 
 9 import os,sys
10 
11 
12 BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13 #拿到整个文件的当前路径D:\Document\Python0404\day5\目录规范\ATM2
14 sys.path.append(BASE_DIR)#添加到环境变量
15 LOG_PATH=os.path.join(BASE_DIR,'log','access.log')
16 
17 from core import src
18 
19 if __name__=='__main__':
20     src.run()
View Code

src.py

 1 """
 2 Description:
 3 Author:Nod
 4 Date:
 5 Record:
 6 #---------------------------------v1-----------------------------------#
 7 """
 8 from bin import start
 9 
10 
11 
12 import time
13 # 记录喝水的记录
14 def record():
15     time_strf=time.asctime()
16     msg='Nod has drink at %s'%time_strf
17     with open(start.LOG_PATH, 'a', encoding='utf-8') as f:
18         f.write('%s\n' % msg)
19 
20 #查看喝水的时间
21 def checkRecord():
22     with open(start.LOG_PATH, 'r', encoding='utf-8') as f2:
23         data=f2.read()
24     print('==========================>查看饮水记录<=========================')
25     print(data)
26     print('==========================>饮水记录结束<=========================')
27 #退出程式
28 def Quit():
29     exit('退出程式')
30 
31 
32 def run():
33     message = """
34 
35     welcome to drink water record
36 
37     1  record
38     2  checkRecord
39     3  Quit
40 
41     """
42     while True:
43         print(message)
44         user_choice=input('请输入你的选择:>>>>').strip()
45         if not user_choice:continue
46         if user_choice=='1':
47             record()
48         elif user_choice=='2':
49             checkRecord()
50         elif user_choice=='3':
51             Quit()
52 
53 
54 
55 
56 if __name__=='__main__':
57     run()
View Code

 

转载于:https://www.cnblogs.com/nodchen/p/9074886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值