• 文件的增删改查


    #author:徐征
    def look():
        while 1:
            x=input('查看:如www.oldboy.org
    ').strip()
            n=[]
            flag=False
            with open("haproxy.conf",encoding="utf8") as f_read:
                for line in f_read:
                    if line.startswith("backend") and x in line:
                        flag=True
                        continue
                    if line.startswith("backend") and flag:
                        break
                    if flag:
                        n.append(line.strip())
                for i in n:
                    print(i)
    def delete():
        x=input('删除:如www.oldboy.org
    ').strip()
        with open("haproxy.conf",encoding="utf8") as f_read,open("test",mode="w",encoding="utf8") as f1_read:
            for line in f_read:
                f1_read.write(line)
                if line.startswith("backend") and x in line:
                    break
    def increase():
        x = input('修改:如www.oldboy.org
    ').strip()
        i="        server 11111 weight 2222 maxconn 3333"
        with open("haproxy.conf", encoding="utf8") as f_read, open("test", mode="w", encoding="utf8") as f1_read:
            for line in f_read:
                f1_read.write(line)
                if line.startswith("backend") and x in line:
                    f1_read.write(i)
                    break
    def add():
        x = input('增加:如www.oldboy.org
    ').strip()
        i = "        server 11111 weight 2222 maxconn 3333,
    "
        with open("haproxy.conf", encoding="utf8") as f_read, open("test", mode="w", encoding="utf8") as f1_read:
            for line in f_read:
                f1_read.write(line)
                if line.startswith("backend") and x in line:
                    f1_read.write(i)
    def msg():
        xzh='''
        *******************************
         1.look 查看
         2.delete 删除
         3.increase 修改
         4.add  增加
         0.exit 退出
        ******************************* 
        '''
        print(xzh)
    def mains():
        msg()
        while 1:
            q = int(input("必须输入0,1,2,3,4这四个数字
    输入需要使用的功能编号--->:"))
            if q==0:
                print("再见!")
                exit()
            if q==1:
                look()
            if q==2:
                delete()
            if q==3:
                increase()
            if q==4:
                add()
    mains()
  • 相关阅读:
    升级python
    python内置函数整理
    import 搜索路径
    webpy 解决中文出现UnicodeDecodeError: 'ascii' codec can't decode byte 问题
    未预期的符号 `$'{ '' 附近有语法错误
    python引入模块时import与from ... import的区别
    "Native table 'performance_schema'.'session_variables' has the wrong structure") [SQL: "SHOW VARIABLES LIKE 'sql_mode'"]
    git命令
    Redis简介
    MongoDB基本操作
  • 原文地址:https://www.cnblogs.com/xuzheng940806/p/6685931.html
Copyright © 2020-2023  润新知