内容

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. Java只给汉字转URLEncoder

    public static String encode(String str, String charset) throws UnsupportedEncodingException { Patter ...

  2. JS快速构建数组方法

    一.常用(普通)数组的构建 1.1 直接构建 let arr = ['mock1', 'mock2', 'mock3'] 1.2 通过new Array let arr = newArray('moc ...

  3. 基于 Python 和 Pandas 的数据分析(5) --- Concatenating and Appending

    这一节我们将会介绍几种不同的合并数据的方法. 在我们这个不动产投资的例子中, 我们希望获取 51 个州的房产数据, 并把它们组合起来. 我们这样做有很多原因. 这样做既便于我们做分析, 同时也可以占用 ...

  4. python 目录切换

    #- * -coding: utf - - * - import os, sys path = "c:\\" # 查看当前工作目录 retval = os.getcwd() pri ...

  5. 软件测试中Bug的生命周期以及Bug的严重等级

    软件测试中Bug的生命周期以及Bug的严重等级 我猜你们都会,但能说专业且全面不? 1.首先当测试人员接到一个项目或产品准备测试的时候,测试人员会根据测试用例一步步的来执行用例进行简单的功能测试.当测 ...

  6. Java SE HashMap的底层实现

    1.hash散列算法 由于hashmap在存储过程中是数组加链表的存储过程,所以定义数组长度为16(建议是2的n次幂的长度),之后进行每个数组的地址都指向一个链表进行存储 hash表算法可对数组长度l ...

  7. java添加templates模板,httpServlet模板改写

    为了提高开发效率,通常将一些常用模板添加到快捷键,方法: window-prefrerences-java-editor-templates 代码复制进去apply应用即可 package com.l ...

  8. 导入dmp文件时,需要删除原有ORACLE数据库实例

    导入dmp文件时,对于已存在的数据库实例及表处理方式:删除实例. 1.以管理员身份登录 sqlplus / as sysdba 2.停止实例 shutdown abort; 执行结果:ORACLE i ...

  9. .NET Core 管道

    从用户发请求到服务器响应返回数据 请求从 Request进去    先经过 Middleware(中间件) 然后经过AuthoriationFilters授权验证(token验证和 多租户验证) 在经 ...

  10. vue-cli webpack打包不.map文件,iview 项目打包完,图标路径有问题

    vue 项目打包出来有时候体积有点大,其实基本都是.map文件比较大,这些文件对项目没什么影响,可以直接在打包时候就不生成.map文件这样就不用每次删那么麻烦了, 做法: config中知道 inde ...