码迷,mamicode.com
首页 > 编程语言 > 详细

python自动化运维之路~DAY1

时间:2016-12-12 14:33:49      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:match   password   密码   lease   als   bsp   自动化   with   ati   

技术分享

刚学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

标签:match   password   密码   lease   als   bsp   自动化   with   ati   

原文地址:http://www.cnblogs.com/yinzhengjie/p/6163999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!