#Author by Andy
#_*_ coding:utf-8 _*_
import sys
import time
Path="E:\my python study\\files\haproxy.txt"
Path_new="E:\my python study\\files\haproxy_new.txt"
examples='''\033[31;1m内容格式范例 :
arg={
'backend': 'www.oldgirl.org',
'record':{
'server': '100.1.7.10',
'weight': 20,
'maxconn': 30
}
}
\033[;0m'''
#定义主函数
def main_func():
print("Welcome to use this program!")
choice=input("See what you can do:\n"
"Add\n"
"Delete\n"
"Q or q to end program.\n"
"Search\n"
":")
return choice
#定义字符串转字典函数
def str_to_dict():
print("请输入要添加的内容:")
stop_input = ''
user_input = ''
for line in iter(input,''):
user_input = user_input+line + '\n' #input遇到空行才停止,默认是遇到回车停止
dict = eval(user_input.strip("arg = "))
return dict
#定义追加函数
def add(info):
backend_value=info['backend']
record_value=info['record']
f=open(Path,'a+',encoding='utf-8')
f.write('\nbackend %s \n' %backend_value)
f.write('\t\tserver %s weight %s maxconn %s\n'
%(record_value['server'],record_value['weight'],record_value['maxconn']))
time.sleep(2)
f.closed
# add(str_to_dict())
#定义删除函数
def dele(info):
backend_value=info['backend']
record_value=info['record']
del_record='\t\tserver %s weight %s maxconn %s\n' \
%(record_value['server'],record_value['weight'],record_value['maxconn'])
f = open(Path,'r+',encoding='utf-8')
f_new=open(Path_new,'w',encoding='utf-8')
for line in f:
if backend_value in line:
line=line.replace(line,'')
elif del_record == line:
line=line.replace(del_record,'')
f_new.write(line)
time.sleep(2)
f.closed
f_new.closed
#dele(str_to_dict()) def find_keywords(keywords):
f=open(Path,'r+',encoding='utf-8')
while True:
line = f.readline()
if keywords in line:
f.seek(f.tell()+1)
print(f.readline().strip())
target=f.readline().strip()
time.sleep(2)
f.closed
return target
while True:
choice=main_func()
if choice=='Add':
print(examples)
add(str_to_dict())
elif choice=='Search':
keywords=input("请输入关键字:")
find_keywords(keywords)
elif choice=='Delete':
print(examples)
dele(str_to_dict())
elif choice=='q'or choice =='Q':
print("Bye-bye!")
exit() 文件格式:
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.oldboy1.org
use_backend www.oldboy1.org if www backend www.oldboy.org
server 100.1.7.9 100.1.7.9 weight 20 maxconn 3000 需求:
1、查
输入:www.oldboy.org
获取当前backend下的所有记录 2、新建
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
} 3、删除
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
}

python3 文件增删查的更多相关文章

  1. linus上运行jar包文件增删查

    package com.osplat.util; import com.alibaba.fastjson.JSON; import com.osplat.bean.Resultmodel; impor ...

  2. HDFS Java Client对hdfs文件增删查改

      step1:增加依赖 pom.xml           ...      <!-- https://mvnrepository.com/artifact/org.apache.hadoop ...

  3. 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  4. 4.在MVC中使用仓储模式进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...

  5. 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  6. hibernate基础增删查改简单实例

    hibernate 基础理论知识网上很多,可以百度和google.这里不做多的介绍,以一个User表来开展例子 建一个web-project 我这里用了junit单元测试环境来进行增删查改的测试,别的 ...

  7. 8天学通MongoDB——第二天 细说增删查改

    原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...

  8. [置顶] cocos2dx sqllite 增删查改等操作

    首先导入文件shell.c sqllite3.c sqlite3.h sqlite3etx.h文件(注意在生成安卓项目是 不要将shell.c写进android.mk文件中,写进去在cywin中生成会 ...

  9. 一套手写ajax加一般处理程序的增删查改

    倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...

随机推荐

  1. css3基础必回选择器全解

    1.   *:通用元素选择器   * { margin: 0; padding: 0; } *选择器是选择页面上的全部元素,上面的代码作用是把全部元素的margin和padding设为0,最基本的清除 ...

  2. WebService "因 URL 意外地以 结束,请求格式无法识别" 的解决方法

    最近在做一个图片上传的功能,js调用用webservice进行异步访问服务器,对于不是经常用webservice的菜鸟来说,经常会遇到以下的问题(起码我是遇到了) 在页面上写了js调用代码如下所示: ...

  3. 在.NET中使用JQuery 选择器精确提取网页内容

    1. 前言 相信很多人做开发时都有过这样的需求:从网页中准确提取所需的内容.思前想后,方法无非是以下几种:(本人经验尚浅,有更好的方法还请大家指点) 1. 使用正则表达式匹配所需元素.(缺点:同类型的 ...

  4. Spring实现IOC

    目录 一.使用XML配置的方式实现IOC 二.使用Spring注解配置IOC 三.自动装配 四.零配置实现IOC 五.示例下载 控制反转IoC(Inversion of Control),是一种设计思 ...

  5. 工作中总结的常用PHP代码

    [目录] ◆PHP常用的代码 ◆HTML常用代码 [值传递 和 引用传递] [单例模式] [魔术常量] [代码调试(自定义一个简单的debug函数)] [thinkphp多表查询] [获取客户端IP地 ...

  6. JS表单验证

    1. 长度限制 <script> function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符 ...

  7. OFDM学习之旅

    前言: 这些日子开始准备搞OFDM之类的,未动先行matlab仿真,这里我会慢慢更新,基本上是自己学习感悟吧<未完待续> 一.PRBS PRBS 是 Pseudo Random Binar ...

  8. 前端利器---Bootstrap

    看着那么多大神在博客上都有自己的心得和分享,我虽然工作不久,但也想做一下自己的笔记起码对自己是一次积累和锻炼的过程.所以心血来潮今天就注册了博客. 我今天想说一下Bootstrap,学前台的大概对Bo ...

  9. ServerSocket

    在网上找ServerSocket看到的解释

  10. 创建EF数据模型

    最后的应用程序,看上去就像下边这样: 创建数据模型,你将从以下三个类开始: 在Models文件夹,新建以下类: using System; using System.Collections.Gener ...