標籤: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,sys10 11 12 BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))13 #拿到整個檔案的當前路徑D:\Document\Python0404\day5\目錄規範\ATM214 sys.path.append(BASE_DIR)#添加到環境變數15 LOG_PATH=os.path.join(BASE_DIR,‘log‘,‘access.log‘)16 17 from core import src18 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 time13 # 記錄喝水的記錄14 def record():15 time_strf=time.asctime()16 msg=‘Nod has drink at %s‘%time_strf17 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 record36 37 1 record38 2 checkRecord39 3 Quit40 41 """42 while True:43 print(message)44 user_choice=input(‘請輸入你的選擇:>>>>‘).strip()45 if not user_choice:continue46 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
Python 樣本 飲水記錄