标签:put tin date 文件的 img open 目录结构 结构 one
因为每天都需要喝水 这是非常重要的
目录结构:
├─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()
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()
标签:put tin date 文件的 img open 目录结构 结构 one
原文地址:https://www.cnblogs.com/nodchen/p/9074886.html