码迷,mamicode.com
首页 > 编程语言 > 详细

python练习题_04

时间:2019-04-04 17:11:42      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:main   pytho   enc   break   lin   add   数据   continue   pass   

import os

def fetch(data):
    # print(‘\033[1;43m这是查询功能\033[0m‘)
    # print(‘\033[1;43m用户数据是\033[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\n%( *8,data[0][record][sever],
                                                 data[0][record][weight])
    new_sever_record=%s sever %s weight %s\n%( *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\n%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

标签:main   pytho   enc   break   lin   add   数据   continue   pass   

原文地址:https://www.cnblogs.com/Manuel/p/10655833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!