Python 樣本 飲水記錄

來源:互聯網
上載者:User

標籤: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 樣本 飲水記錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.