How to record user login log by python
This article mainly explains "how to record user login log in python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to record user login logs by python".
Task 1. Log the user login log import timedef show_info (): print ('enter the prompt number and perform the corresponding action: 0 exit) 1 View login log') # record log def write_logininfo (username): with open ('log.txt','a') as file: username {username}, login time: {time.strftime ("% Y-%m-%d% log") Time.localtime (time.time ())} 'file.write (s) file.write ('\ n') # read log def read_logininfo (): with open ('log.txt','r') as file: while True: line=file.readline () if line=='': break else: print (line End='\ t') if _ _ name__ ='_ _ main__': username=input ('Please enter your user name:') pwd=input ('Please enter your password:') if 'admin'==username and' admin'==pwd: print ('login succeeded!') Write_logininfo (username) # logging show_info () # prompts the user what to do num=int ('enter operation number:') while True: if num==0: print ('exit successful') break elif num==1: print ('view login log') Read_logininfo () # read date num=int (input ('input Operand number:') else: print ('you entered the wrong number!') Show_info () num = int (input ('enter Operand number:') else: print ('Sorry, the username or password is incorrect!') '' print (time.time ()) # seconds print (time.localtime (time.time () print (time.strftime ('% Y-%m-%d% HGV% MV% Scramco time.localtime (time.time () Task 2, simulate the automatic reply of Taobao customer service
At this point, I believe you have a deeper understanding of "how to record user login logs in python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!