内容

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. HDU 1403 Longest Common Substring(最长公共子串)

    http://acm.hdu.edu.cn/showproblem.php?pid=1403 题意:给出两个字符串,求最长公共子串的长度. 思路: 刚开始学后缀数组,确实感觉很难,但是这东西很强大,所 ...

  2. Web前端新手经典学习路线

    做前端开发八九年的时间,到2015年的时候,Web前端因为HTML5技术的高速发展,成为IT行业中最受欢迎和未来需求人才发展最好的职业,各个行业都想转行做前端开发,包括一些在校的学生,土木工程,一些不 ...

  3. PHP 常见的数据加密技术

    单项散列加密技术(不可逆的加密) 把任意长的输入字符串变化为固定长的输出串的一种函数 MD5 string md5 ( string $str [, bool $raw_output = false ...

  4. appium长按按钮

    public static AndroidDriver driver; /长按操作:waitAction的参数单位是ms/ public static void longClick(String id ...

  5. bean标签常用属性

    scope属性: singleton:只有一个 prototpye:每次创建都是新的 对象初始化方法: init-method 对象销毁方法: destroy-method

  6. React native 之设置IOS的图标,名称和启动图(下篇文章会讲到RN的android的相关设置)

    1.首先,app的名称: 如图所示:我的工程名叫BOOk 在BOOk下面的info.plist的文件里设置app的相关信息:比如Bundle name就是设置APP的名称 2.App的图标:(这里注意 ...

  7. 【六】php 错误异常处理

    错误异常处理 概念:代码在try代码块被调用执行,catch代码块捕获异常 异常需要手动抛出 throw new Exception (‘message’,code) throw将出发异常处理机制 在 ...

  8. phpredis基本操作

    字符串,用于存储变动少的信息 创建对象 $red = Red::create(); 设置值 $red->set('name','张三'); 设置有效期 $red->set('name',' ...

  9. 力扣(LeetCode)965. 单值二叉树

    如果二叉树每个节点都具有相同的值,那么该二叉树就是单值二叉树. 只有给定的树是单值二叉树时,才返回 true:否则返回 false. 思路 递归 java版 /** * Definition for ...

  10. 力扣(LeetCode)922. 按奇偶排序数组 II

    给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数. 对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数:当 A[i] 为偶数时, i 也是偶数. 你可以返回任何满足上述条件的数组 ...