#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. mbed学习之Digital IO (一)

    mbed的IO操作非常灵活,常见的关于Digital IO操作整理如下表 ,其中蓝色字体是构造函数,绿色字体的是操作符重载,使用时只要创建对象,就可以调用对应的方法来操作,并且每种都提供了操作符重载, ...

  2. Mono.Ceil 无法保存Silverlight 程序集

    一句话: 处理Silverlight程序集之前, 须先移除强名称(StrongNameRemoveHelper), 之后Reflexil 即可一如预期的正常工作.

  3. Linux:-防火墙iptables如何个性化定制?

    身份标签/usr/local/etc/identity,主脚本iptables.sh,附属目录functions/iptables.d ├── iptables.sh ├── functions│   ...

  4. 我的Android第一章

    一.android是什么 基于linux系统下开发的开源系统 二.android的具体架构是什么 硬件[智能设备底层的硬件],驱动[软件和硬件之间沟通的桥梁],Linux系统[一款功能强大代码开源的系 ...

  5. easyui DataGrid 工具类之 后台生成列

    @SuppressWarnings({ "rawtypes", "unchecked" })    public Map<String, Object&g ...

  6. nodejs路由的部分通配

    1. 占位标识符/:id app.get('/post_api_post_data_ren/bet/follow/:gameEn',function(req,res){ console.log(req ...

  7. 【jQuery】【转】jQuery中的trigger和triggerHandler区别

    trigger(event, [data]) 在每一个匹配的元素上触发某类事件. 这个函数也会导致浏览器同名的默认行为的执行.比如,如果用trigger()触发一个'submit',则同样会导致浏览器 ...

  8. 高效 JavaScript

    高效 JavaScript 原译文地址 http://kb.operachina.com/node/207 传统上,网页中不会有大量的脚本,至少脚本很少会影响网页的性能.但随着网页越来越像 Web 应 ...

  9. 在Windows系统下用命令把应用程序添加到系统服务

    在Windows系统下用命令把应用程序添加到系统服务,使用SC命令. 加入服务格式如下:sc create ServiceName binPath= 程序路径 start= auto(等号后面的空格是 ...

  10. Css绘制圆形,环形,椭圆等图形

    转载自http://blog.csdn.net/gongstrong123/article/details/50888758 绘制圆形,环形,椭圆 <!DOCTYPE html> < ...