python练习题_04

Posted Manuel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python练习题_04相关的知识,希望对你有一定的参考价值。

import os

def fetch(data):
    # print(‘33[1;43m这是查询功能33[0m‘)
    # print(‘33[1;43m用户数据是33[0m‘,data)
    backend_data=backend %s%data
    with open(website.conf,r,encoding=utf-8) as read_f:
        tag = False
        ret = []
        for read_line in read_f:
            if  read_line.strip()==backend_data:
                tag=True
                continue
            if tag and read_line.startswith(backend):
                break
            if tag:
                print(read_line,end=‘‘)
                ret.append(read_line)
        return ret

def add():
    pass

def change(data):
    print(这是修改功能)
    backend= data[0][backend]
    backend_data=backend %s%backend
    old_sever_record=%s sever %s weight %s
%( *8,data[0][record][sever],
                                                 data[0][record][weight])
    new_sever_record=%s sever %s weight %s
%( *8,data[1][record][sever],
                                               data[1][record][weight])

    res=fetch(backend)
    print(change函数,res)

    # if not res or old_sever_record not in res:
    #     return ‘你要修改的记录不存在‘
    # else:
    index=res.index(old_sever_record)
    res[index]=new_sever_record
    res.insert(0,%s
%backend_data)
    with open(website.conf,r) as read_f,        open(website_new.conf,w) as write_f:
        tag=False
        has_wirte=False
        for read_line in read_f:
            if  read_line.strip()==backend_data:
                tag=True
                continue
            if tag and read_line.startswith(backend):
                tag=False
            if not tag:
                write_f.write(read_line)
            else:
                if  not has_wirte:
                    for record in res:
                        write_f.write(record)


def delete():
    pass

if __name__==__main__:
    msg=‘‘‘
    1.查询
    2.添加
    3.修改
    4.删除
    5.退出
    ‘‘‘
    msg_dic={
        1:fetch,
        2:add,
        3:change,
        4:delete
    }


    while True:
        print(msg)
        choice=input(请输入你的选项:).strip()
        if not choice:continue
        if choice==5:break
        data=input(请输入你的数据:.strip())
        if choice!=1:
            data=eval(data)
        res=msg_dic[choice](data)
        print(res)


# [{‘backend‘:‘www.newboy2.org‘,‘record‘:{‘sever‘:‘1.1.1.8‘,‘weight‘:80}},{‘backend‘:‘www.newboy2.org‘,‘record‘:{‘sever‘:‘1.0.0.8‘,‘weight‘:100}}]

 

以上是关于python练习题_04的主要内容,如果未能解决你的问题,请参考以下文章

Python-23_装饰器-04_练习---无参装饰器有参装饰器

Python之练习数学运用代码

python小练习--函数调用函数,让对象具有能动性

Python3练习题系列(04)

python练习题之访问限制

如何在 python 中并行化以下代码片段?