python操作文件(增、删、改、查)
内容
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操作文件(增、删、改、查)的更多相关文章
- php5.4以上 mysqli 实例操作mysql 增,删,改,查
<?php //php5.4以上 mysqli 实例操作mysql header("Content-type:text/html;charset=utf8"); $conn ...
- 好用的SQL TVP~~独家赠送[增-删-改-查]的例子
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列主要是针对T-SQL的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...
- iOS sqlite3 的基本使用(增 删 改 查)
iOS sqlite3 的基本使用(增 删 改 查) 这篇博客不会讲述太多sql语言,目的重在实现sqlite3的一些基本操作. 例:增 删 改 查 如果想了解更多的sql语言可以利用强大的互联网. ...
- django ajax增 删 改 查
具于django ajax实现增 删 改 查功能 代码示例: 代码: urls.py from django.conf.urls import url from django.contrib impo ...
- iOS FMDB的使用(增,删,改,查,sqlite存取图片)
iOS FMDB的使用(增,删,改,查,sqlite存取图片) 在上一篇博客我对sqlite的基本使用进行了详细介绍... 但是在实际开发中原生使用的频率是很少的... 这篇博客我将会较全面的介绍FM ...
- ADO.NET 增 删 改 查
ADO.NET:(数据访问技术)就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中 也可以将数据库中的数据提取到内存中供程序调用 ADO.NET所有数据访 ...
- MVC EF 增 删 改 查
using System;using System.Collections.Generic;using System.Linq;using System.Web;//using System.Data ...
- python基础中的四大天王-增-删-改-查
列表-list-[] 输入内存储存容器 发生改变通常直接变化,让我们看看下面列子 增---默认在最后添加 #append()--括号中可以是数字,可以是字符串,可以是元祖,可以是集合,可以是字典 #l ...
- 简单的php数据库操作类代码(增,删,改,查)
这几天准备重新学习,梳理一下知识体系,同时按照功能模块划分做一些东西.所以.mysql的操作成为第一个要点.我写了一个简单的mysql操作类,实现数据的简单的增删改查功能. 数据库操纵基本流程为: 1 ...
- django单表操作 增 删 改 查
一.实现:增.删.改.查 1.获取所有数据显示在页面上 model.Classes.object.all(),拿到数据后,渲染给前端;前端通过for循环的方式,取出数据. 目的:通过classes(班 ...
随机推荐
- hostname命令
hostname命令用于显示和设置系统的主机名称.环境变量HOSTNAME也保存了当前的主机名.在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名. ...
- Vue--vux组件库
各种组件demo源码~ https://doc.vux.li/zh-CN/
- 学习笔记28—Python 不同数据类型取值方法
1.array数据类型 1)-------> y[i,] 或者 y[i] 2.遍历目录下所有文件夹: def eachFile(filepath): pathDir = os.list ...
- Hive json字符串解析
在做数据测试时,会遇到数据库表里字段类型为json 的情况,而我们可能只关注该字段中的各别内容的信息,如下 content {"测试内容1":,"测试内容2": ...
- spring cloud: zuul: 微网关-简单使用与路由配置
spring cloud: zuul: 微网关-简单使用与路由配置 首先引入依赖 <dependency> <groupId>org.springframework.cloud ...
- Alibaba Java诊断工具Arthas之快速安装和简单使用
Alibaba Java诊断工具Arthas简单介绍 : 当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决: 1.这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception ...
- 树分治TLE原因
1.树分治有logn层,如果各层都进行一次memset相当于大小没变,可能TLE: 2.根节点全局变量会变,需要用局部变量记录,还有子树大小. 3.找根的时候的size是当前size,而不是输入数据中 ...
- Create a Hadoop Build and Development Environment
Create a Hadoop Build and Development Environment http://vichargrave.com/create-a-hadoop-build-and-d ...
- Linux中计划任务、周期性任务设置
Linux中计划任务.周期性任务设置 计划任务:指在未来的特定时间里,执行一次某一特定任务.当然,如果同一任务需要在不同时间点执行执行两次.三次或多次,可以视为多个一次看待. 周期性任务:指某一任务需 ...
- Power Of Two leetcode java
问题描述: Given an integer, write a function to determine if it is a power of two. 问题分析:给定一个数,判断它是不是2的幂. ...