内容

global
log 127.0.0.1 local2
daemon
maxconn 256
log 127.0.0.1 local2 info
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option dontlognull listen stats :8888
stats enable
stats uri /admin
stats auth admin:1234 frontend oldboy.org
bind 0.0.0.0:80
option httplog
option httpclose
option forwardfor
log global
acl www hdr_reg(host) -i www.oldboy.org
use_backend www.oldboy.org if www backend www.oldboy1.org
server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333
server 10.10.10.1 10.10.10.1 weight 22 maxconn 2000
server 2.2.2.4 2.2.2.4 weight 20 maxconn 3000
backend www.oldboy2.org
server 3.3.3.3 3.3.3.3 weight 20 maxconn 3000
backend www.oldboy20.org
server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333

 arg = {'backend': 'www.oldboy.org','record':{'server':'10.10.0.10 10.10.0.10',"weight":"", "maxconn": ""}}
count=0
while True:
choice=eval(input("请输入一个字典{}"))
with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
for line in a:
count+=1
if count==26:
b.write (str(choice["backend"]))
b.write('\n')
b.write(str(choice["record"]).strip('{}'))
else:b.write(line)

删除:

import sys, time
count=0
l=[]
while True:
with open( "haproxy.conf",'r') as a:
for i in a:
count+=1
print(i,count)
else:
count=0
print(count)
choice=input("请输入要删除的行---->:").strip()
for i in choice:
if i.isdigit():
l.append(int(i))
with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
for line in a:
count+=1
if count in l:
continue
else:
b.write(line)
for i in l:
sys.stdout.write("\r ##########正在删除第%s行#########" % i)
sys.stdout.flush()
time.sleep(1)
exit(print('\n 再见!'))
arg = {'backend': 'www.oldboy.org','record':{'server':'10.10.0.10 10.10.0.10',"weight":"9999", "maxconn": "33333333333"}}

while True:
choice = eval(input("请输入一个字典{}:").strip())
with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
for line in a:
if line.startswith("backend") and choice["backend"] in line:
continue
if choice["record"]['server'] in line:
continue
else:
b.write(line)

删2:

  

count=0
while True:
with open( "haproxy.conf",'r') as a:
for i in a:
count+=1
print(i,count)
else:
count=0
print(count)
choice=int(input("请输入删除的行:"))
print(choice)
with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
for line in a:
count+=1
if count==choice:
continue
else:
b.write(line)

count=
while True:
choice=eval(input("请输入一个字典{}")) # choice=eval(input("请输入一个字典{}"))
with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
for line in a:
count+=
if count==:
b.write(str(choice["backend"]).strip())
continue
if count==:
b.write("\n")
continue
if count==:
for k,v in dict(choice['record']).items():
b.write(' ')
b.write(k)
b.write(" ")
b.write(v)
continue
if count==:
b.write("\n")
continue
else:
b.write(line)

 while True:
l=[]
m=input("请输入您要查询的内容: ").strip()
flag=False
with open('haproxy.conf','r') as ha1:
for line in ha1:
if line.startswith("backend") and m in line: #第一步 定位到 backend行
flag=True
continue
if flag==True: #第二步 设置标志开关
l.append(line)
if line.startswith("backend") and flag: #第三步 跳出循环
break
for i in l:
print(i)

用户登录三次锁定:

count=0
while True:
user=input("请输入您的用户名: ").strip()
with open("lock_account",'r') as a:
for i in a:
if user==i.strip():
exit("您的账户已被锁定")
password = input("请输入密码: ").strip()
count+=1
flag = False
with open("account.txt", 'r') as b:
for line in b:
use,psw = line.strip().split()
if user== use and password==psw:
count=0
print("---------欢迎登录-------- ") if count==3 and flag==False:
with open("lock_account", 'a') as a:
a.write(user)
a.write('\n')
exit("输入次数超过3次,你的账户被锁定了")

定义函数精简版

count=0
def open_lockaccount(user):
with open("lock_account",'r') as a:
for i in a:
if user==i.strip():
exit("您的账户已被锁定")
def open_account(user,passwd):
with open("account.txt", 'r') as b:
for line in b:
use,psw = line.strip().split()
if user== use and password==psw:
count = 0
print("---------欢迎登录-------- ")
def write_account(user):
with open("lock_account", 'a') as a:
a.write(user)
a.write('\n')
exit("输入次数超过3次,你的账户被锁定了")
while True:
user=input("请输入您的用户名: ").strip()
open_lockaccount(user)
password = input("请输入密码: ").strip()
count+=1
flag = False
open_account(user, password)
if count == 3 and flag == False:
write_account(user)

python操作文件(增、删、改、查)的更多相关文章

  1. php5.4以上 mysqli 实例操作mysql 增,删,改,查

    <?php //php5.4以上 mysqli 实例操作mysql header("Content-type:text/html;charset=utf8"); $conn ...

  2. 好用的SQL TVP~~独家赠送[增-删-改-查]的例子

    以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化.  本系列主要是针对T-SQL的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...

  3. iOS sqlite3 的基本使用(增 删 改 查)

    iOS sqlite3 的基本使用(增 删 改 查) 这篇博客不会讲述太多sql语言,目的重在实现sqlite3的一些基本操作. 例:增 删 改 查 如果想了解更多的sql语言可以利用强大的互联网. ...

  4. django ajax增 删 改 查

    具于django ajax实现增 删 改 查功能 代码示例: 代码: urls.py from django.conf.urls import url from django.contrib impo ...

  5. iOS FMDB的使用(增,删,改,查,sqlite存取图片)

    iOS FMDB的使用(增,删,改,查,sqlite存取图片) 在上一篇博客我对sqlite的基本使用进行了详细介绍... 但是在实际开发中原生使用的频率是很少的... 这篇博客我将会较全面的介绍FM ...

  6. ADO.NET 增 删 改 查

    ADO.NET:(数据访问技术)就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中 也可以将数据库中的数据提取到内存中供程序调用 ADO.NET所有数据访 ...

  7. MVC EF 增 删 改 查

    using System;using System.Collections.Generic;using System.Linq;using System.Web;//using System.Data ...

  8. python基础中的四大天王-增-删-改-查

    列表-list-[] 输入内存储存容器 发生改变通常直接变化,让我们看看下面列子 增---默认在最后添加 #append()--括号中可以是数字,可以是字符串,可以是元祖,可以是集合,可以是字典 #l ...

  9. 简单的php数据库操作类代码(增,删,改,查)

    这几天准备重新学习,梳理一下知识体系,同时按照功能模块划分做一些东西.所以.mysql的操作成为第一个要点.我写了一个简单的mysql操作类,实现数据的简单的增删改查功能. 数据库操纵基本流程为: 1 ...

  10. django单表操作 增 删 改 查

    一.实现:增.删.改.查 1.获取所有数据显示在页面上 model.Classes.object.all(),拿到数据后,渲染给前端;前端通过for循环的方式,取出数据. 目的:通过classes(班 ...

随机推荐

  1. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

  2. mathType换行等号对齐

    例如: 输入步骤: (1) (2) (3) (4) 事实上,[ctrl+;]表示的是插入了一个对齐标记符.

  3. 小程序之map地图上不能在覆盖层

    问题:页面上有一个地图功能,地图上面有两个按钮,是需要覆盖在地图上的,在小程序编辑器中显示是没问题的,但是扫码测试后发现在手机上不显示这两个按钮 解决方法:使用cover-viwe标签包裹一下就可以了

  4. python redis 操作

    1.String 操作 redis中的String在在内存中按照一个name对应一个value来存储 set() #在Redis中设置值,默认不存在则创建,存在则修改 r.set('name', 'z ...

  5. oracle listagg和wm_concat函数

    对于将一列多值合并成一行问题,oracle提供了wmsys.wm_concat和listagg函数处理此问题,下面我们以emp表中数据为例,看看两函数的使用方法 假设我们需要统计每种job下面有哪些员 ...

  6. HAProxy用法详解

    一.HAProxy简介 (1)HAProxy 是一款提供高可用性.负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProx ...

  7. 写给前端的Python依赖管理指北

    概述 在Python的项目中,我们可以通过pip来安装依赖包,但是不像npm install,pip默认安装的依赖包会挂在全局上,不利于项目工程协作. 这时候需要一款类似npm的工具记录我们的项目依赖 ...

  8. Java == 和 equals 区别

    先来看一段代码 1. String str1 = new String("hello");//堆中分配一块内存,存放"hello",str1 指向内存地址 2. ...

  9. 《剑指offer》第四十五题(把数组排成最小的数)

    // 面试题45:把数组排成最小的数 // 题目:输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼 // 接出的所有数字中最小的一个.例如输入数组{3, 32, 321},则打印出这3 ...

  10. display: none; 与 jq show方法之间的联系

    1. 定义四种常用隐藏元素的方式,然后调用  jq 的 show 方法显示,观察各原先隐藏元素的   display   表现,结合 jq 源码,show 方法设置 元素 display  属性值为 ...