Because it's important to drink water every day.
Directory structure:
├─bin
││start.py
││
│└─__pycache__
│start.cpython-36.pyc
│
├─core
││src.py
││
│└─__pycache__
│src.cpython-36.pyc
│
└─log
Access.log
Code content:
start.py
1 """2 Description:3 Author:nod4 Date:5 Record:6 #---------------------------------v1-----------------------------------#7 """8 9 ImportOs,sysTen One ABase_dir=os.path.dirname (Os.path.dirname (Os.path.abspath (__file__))) - #get the current path to the entire file D:\Document\Python0404\day5\ directory specification \atm2 -Sys.path.append (Base_dir)#Add to environment variable theLog_path=os.path.join (Base_dir,'Log','Access.log') - - fromCoreImportsrc - + if __name__=='__main__': -Src.run ()
View Code
src.py
1 """2 Description:3 Author:nod4 Date:5 Record:6 #---------------------------------v1-----------------------------------#7 """8 fromBinImportStart9 Ten One A Import Time - #record the drinking water record - defrecord (): thetime_strf=time.asctime () -msg='Nod have drink at%s'%TIME_STRF -With open (start. Log_path,'a', encoding='Utf-8') as F: -F.write ('%s\n'%msg) + - #Check the time of drinking water + defCheckrecord (): AWith open (start. Log_path,'R', encoding='Utf-8') as F2: atData=F2.read () - Print('==========================> View drinking water records <=========================') - Print(data) - Print('==========================> drinking Water Records end <=========================') - #Exit Program - defQuit (): inExit'Exit Program') - to + defrun (): -Message =""" the * Welcome to drink water record $ Panax Notoginseng 1 record - 2 Checkrecord the 3 Quit + A """ the whileTrue: + Print(message) -User_choice=input ('Please enter your choice:>>>>'). Strip () $ if notUser_choice:Continue $ ifuser_choice=='1': - record () - elifuser_choice=='2': the Checkrecord () - elifuser_choice=='3':Wuyi Quit () the - Wu - About if __name__=='__main__': $Run ()View Code
Python Sample drinking water record