第一个简单的python脚本
#!/usr/bin/python#import osfile_1='user.txt'file_2='lock.txt'#put an account_listf=file(file_1)accout_list=f.readlines()f.close()#put a list of the lock userf = file(file_2)lock_list= []for i in f.readlines():line = i.strip('\n')lock_list.append(line)f.close()#mainName=raw_input("input the user name:").strip()Password=raw_input("input the user's password:").strip()while True:if len(Name) == 0:print "you user name is blank,do it again"Name=raw_input("input the user name:").strip()continueelif len(Password) == 0:Password=raw_input("input the user's password:").strip()print "your password is blank,do it again"continueelse:breakwhile True:# insert a label to jungle the loginchangeloginchange = Falseif Name in lock_list:print "the user is lock in !"exit()for line in accout_list:line = line.split()# insert a correct usernameif Name == line[0]:loginchange = Truefor i in range(3):if Password == line[1]:breakelse:print "the password is not correct,insert again!"Password=raw_input("input the user's password:").strip()if i == 2:print "the user is lock in !"# insert the wrong user into the lock_filef = file(file_2,'a')f.write('%s\n' %Name)f.close()exit()#continuebreakelse:continueif loginchange is True:breakelse:print "the user is not exist"answer=raw_input("do you want to insert again?(y/n)")if answer == "y" :Name=raw_input("input the user name:").strip()Password=raw_input("input the user's password:").strip()continueelse:exit()print "welcome"