首页 > 代码库 > python自动化运维之路~DAY1
python自动化运维之路~DAY1
刚学python,有大神给指点指点的吗?
#!/usr/bin/env python
#_*_coding:utf8_*_
import getpass,sys
count = 0
match_info = False #用布尔值来标志用户密码是否匹配,默认是flase
while count < 3:
username = input("\033[32;1mAsk you for a username :\033[0m")
with open("locked.txt",‘r‘,encoding="utf-8") as lock_check:
for lock in lock_check.readlines():
lock = lock.split()
type (username)
type (lock)
if username == lock[0]:
sys.exit(‘\033[31;1mSorry, the current user has been locked, please contact the administrator!\033[0m‘)
password = input(‘\033[32;1mAsk you for a password :\033[0m‘)
#password = getpass.getpass(‘\033[32;1mAsk you for a password :\033[0m‘)
with open("user_info.txt",‘r‘,encoding="utf-8") as user_check:
for line in user_check.readlines():
user,passwd = line.strip(‘\n‘).split()
if username == user and password == passwd:
match_info = True
print("You are welcome to use this system", username)
sys.exit()
if match_info == False:
print("The account information you entered is not valid. Please re-enter it and enter the three error to lock the user.")
count += 1
else:
print("You are welcome to use this system", username)
else:
print("Sorry, the user you entered has been locked.")
f = open("locked.txt","a",encoding="utf-8")
f.write(username )
f.close()
运行这个代码之前,要在代码的目录下新建locked.txt和user_info.txt在能执行的哟~
怎么才能把换行符写上去啊~我试过了好多次,都无法将换行符加上去呢~在线等大神指点啊
python自动化运维之路~DAY1
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。