zoukankan      html  css  js  c++  java
  • 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:DocumentPython0404day5目录规范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
    ' % 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
  • 相关阅读:
    使用Application Insights 做分析
    UWP中GridView右击选中的实现
    Bing Map
    UWP深入学习六:Build better apps: Windows 10 by 10 development series
    从上往下打印二叉树
    二叉树中和为某一值的路径
    二叉树的镜像
    树的子结构
    由前序遍历和中序遍历构建二叉树
    二叉树常见题目
  • 原文地址:https://www.cnblogs.com/nodchen/p/9074886.html
Copyright © 2011-2022 走看看