老男孩python自动化运维作业1
#!/usr/bin/env pthon
#字典操作三级菜单 “b”返回上一级菜单,“q”退出。 menu={"BJ":{"cp":{1:1,2:2,3:3},
"ft":{1:4,2:5,3:6}},
"SH":{"lz":{1:1,2:2,3:3}
},
"HK":{"tz":{1:1,2:2,3:3},
"fs":{1:4,2:5,3:6}}}
def one_menu():
for i in range(0,len(menu.keys())):
print(str(i+1) +"."+ menu.keys()[i])
i+=1
one_menu() def tow_menu(city):
menu_list=menu.get(city).keys()
for i in range(0,len(menu_list)):
print (str(i+1) + "." + menu_list[i])
i+=1 def three_menu(city,area): area_menu=menu.get(city).get(area)
for i in range(0,len(area_menu)):
print(area_menu.items()[i]) chose_num="b"
while chose_num !="q":
chose_num=raw_input("please chose menu:") if chose_num =="":
tow_menu("HK") while chose_num !="q":
chose_num=raw_input("please chose menu:") if chose_num=="":
three_menu("HK","fs")
elif chose_num=="":
three_menu("HK","tz")
elif chose_num=="b":
tow_menu("HK")
break
elif chose_num=="q":
exit()
else:
print("input error!") elif chose_num =="":
tow_menu("SH")
while chose_num !="q":
chose_num=raw_input("please chose menu:") if chose_num=="":
three_menu("SH","lz") elif chose_num=="b":
tow_menu("SH")
break
elif chose_num=="q":
exit()
else:
print("input error!")
elif chose_num =="":
tow_menu("BJ")
while chose_num !="q":
chose_num=raw_input("please chose menu:") if chose_num=="":
three_menu("BJ","ft")
elif chose_num=="":
three_menu("BJ","cp")
elif chose_num=="b":
tow_menu("BJ")
break
elif chose_num=="q":
exit()
else:
print("input error!") elif chose_num =="b":
one_menu()
elif chose_num =="q":
exit()
else:
print("input error!")
#文件操作用户登录,提示用户名不存在 和 密码错误,密码错误超过3次则锁定用户登录。
#!/usr/bin/env python
# -*-coding:UTF-8-*-
3
4 def login(): f=open("user",'r') #读取user配置文件。
cont=f.readlines() #readlines把读取的行当作元素返回一个列表
f.close()
allname=[] #初始化一个用户列表
allpasswd=[]
for i in range(0,len(cont)-1): #len获取cont列表的元素数量
onecont=cont[i].split() #循环取一行内容并分割成列表,split()以空格为分隔符分割字符串并返回一个列表。
onename=onecont[0] #循环取一行中的帐号
onepasswd=onecont[1] #
allname.append(onename) #循环把每一行取到的帐号追加到用户列表中
allpasswd.append(onepasswd)
lf=open("user.lock",'r')
lcont=lf.readlines()
lf.close()
# print(lcont) #打印用户锁文件内容
# print(allname)
# print(allpasswd) cont=0
while cont < 3:
username=raw_input("login user:").strip()
passwd=raw_input("password:")
if username not in allname:
print("No this accont!") elif (username +"\n") in lcont:
print("your account has been locked!Please contact admin!")
break
else:
rel_passwd_index=allname.index(username) #取该帐号在用户列表中的索引,此时用户列表的索引和密码列表的索引是对应的,因此我们同样>取到了该帐号的密码在密码列表的索引
rel_passwd=allpasswd[rel_passwd_index] #取该帐号的真实密码
if passwd==rel_passwd:
print("Login success!")
break
else:
print("password is error!")
cont+=1
if cont >= 3:
print("Excessive password error,your account has been locked!Please contact admin!")
nf=open("user.lock",'wb')
nf.write(username+"\n")
nf.close() login()
老男孩python自动化运维作业1的更多相关文章
- 老男孩python自动化运维作业2
拿到要求真不知道怎么写,不能还要写个商城页面吧: 最后还是用了input()模拟用户操作吧- -!不就操作个字典吗(字典模拟商品数据). python版本: >>>import sy ...
- Day1 老男孩python自动化运维课程学习笔记
2017年1月7日老男孩python自动化运维课程正式开课 第一天学习内容: 上午 1.python语言的基本介绍 python语言是一门解释型的语言,与1989年的圣诞节期间,吉多·范罗苏姆为了在阿 ...
- 老男孩Python自动化运维视频
链接:https://pan.baidu.com/s/1VLXJ0RZr39kpSGthkLkgmA 密码私聊我
- python自动化运维学习第一天--day1
学习python自动化运维第一天自己总结的作业 所使用到知识:json模块,用于数据转化sys.exit 用于中断循环退出程序字符串格式化.format字典.文件打开读写with open(file, ...
- Python自动化运维:技术与最佳实践 PDF高清完整版|网盘下载内附地址提取码|
内容简介: <Python自动化运维:技术与最佳实践>一书在中国运维领域将有“划时代”的重要意义:一方面,这是国内第一本从纵.深和实践角度探讨Python在运维领域应用的著作:一方面本书的 ...
- 【目录】Python自动化运维
目录:Python自动化运维笔记 Python自动化运维 - day2 - 数据类型 Python自动化运维 - day3 - 函数part1 Python自动化运维 - day4 - 函数Part2 ...
- python自动化运维篇
1-1 Python运维-课程简介及基础 1-2 Python运维-自动化运维脚本编写 2-1 Python自动化运维-Ansible教程-Ansible介绍 2-2 Python自动化运维-Ansi ...
- Python自动化运维的职业发展道路(暂定)
Python职业发展之路 Python自动化运维工程 Python基础 Linux Shell Fabric Ansible Playbook Zabbix Saltstack Puppet Dock ...
- Python自动化运维 技术与最佳实践PDF高清完整版免费下载|百度云盘|Python基础教程免费电子书
点击获取提取码:7bl4 一.内容简介 <python自动化运维:技术与最佳实践>一书在中国运维领域将有"划时代"的重要意义:一方面,这是国内第一本从纵.深和实践角度探 ...
随机推荐
- spring 注入静态变量
import java.util.Iterator; import java.util.LinkedList; import javax.annotation.PostConstruct; impor ...
- spring mvc <mvc:default-servlet-handler /> 。
spring mvc配置 <mvc:default-servlet-handler /> 时. 提示 The prefix "mvc" for element &quo ...
- 获取View到顶部的高度
tv_title.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener ...
- rabbitMQ学习(五)
topic匹配模式,topic能满足匹配结果就行. 发送端: public class EmitLogTopic { private static final String EXCHANGE_NAME ...
- 微服务实战系列--Nginx官网发布(转)
这是Nginx官网写的一个系列,共七篇文章,如下 Introduction to Microservices (this article) Building Microservices: Using ...
- Kibana安装与基本用法
Kibana也是一个开源和免费的工具,他可以帮助您汇总.分析和搜索重要数据日志并提供友好的web界面.他可以为Logstash 和ElasticSearch 提供日志分析的Web界面 它是一个基于浏览 ...
- Nginx开启GZIP来压缩网页
HTTP协议上的GZIP编码是一种用来改进web应 用程序性能的技术.大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度.这一般是指WWW服务器中安装的一个功能,当有人来访问这个服务器中 ...
- css3新属性
CSS calc()函数来制作响应式网格: calc是英文单词calculate(计算)的缩写,是css3的一个新增的功能,你可以使用calc()给元素的border.margin.pading.fo ...
- Python 2.7_初试连接Mysql查询数据导出到excel_20161216
由于每天到公司都需要先执行一遍检测操作,观察数据是否导入完整,今天想到能否自动连接Mysql执行SQL并导出数据,每天到公司直接查看excel文件即可 时间紧,代码初次试验,边摸索边学习吧. xlsx ...
- Linux文件查找
Linux下查找文件的命令有两个; locate: find : locate这个命令对其生成的数据库进行遍历(生成数据库的命令:updatedb),这一特性决定了查 找文件速度很快,但是locate ...