zoukankan      html  css  js  c++  java
  • 文件的增删改查

    def delect():
        '删除一行信息'
    # m = www.oldboy2.org
        while 1 :
            flag = False
            m = input('please input which url you want to delect:')
            with open('haproxy.conf',encoding = 'utf8') as f_read,open('delect','w',encoding = 'utf8') as f_write:
                for line in f_read:
                    if line.startswith('backend')and m in line :
                        flag = True
                        continue
                    if line.startswith('backend') and flag :
                        flag = False
                    if flag :
                            continue
                    f_write.write(line)
            if m == 'q':
                exit()
    def select():
        '查找一行信息'
        #m = www.oldboy2.org
        while 3:
            m = input('please input which url you want to selet:')
            l = []
            flag = False
            with open('haproxy.conf', encoding='utf8')as f_read:
                for line in f_read:
                    if line.startswith('backend') and m in line:
                        flag = True
                        continue
                    if line.startswith('backend') and flag:
                        flag = False
    
                    if flag:
                        l.append(line.strip())
    
            for i in l:
                print(i)
            if m == 'q':
                exit()
    def insert():
        '增加一些信息'
        while 1:
            url =  input ('please input the url')
            ttt = input('please input what you what to insert:')
            with open('haproxy.conf', encoding='utf8')as f_read,open('insert','a',encoding = 'utf8')as f_write:
                for line in f_read:
                    if line.startswith('backend') and url in line:
                        f_write.write(line)
                        f_write.write('		'+ttt+'
    ')
                    else:
                        f_write.write(line)
            if url == 'q':
                exit()
    def change():
        '改变某一行的信息'
        l = []
        flag = True
        while 1:
            url =  input ('please input the url:')
            with open('haproxy.conf', encoding='utf8')as f_read:
                for line in f_read:
    
                    if line.startswith('backend') and url in line:
                        flag = False
                        continue
                    if line.startswith('backend') and flag == False:
                        flag = True
                    if flag == False:
                        l.append(line.strip())
            print(l)
            ttt = input('please input what you what to change:')
            ccc = input('please input what you want to write:')
            l[l.index(ttt)]= ccc
            with open('haproxy.conf', encoding='utf8')as f_read,open('change', 'a', encoding='utf8')as f_write:
                for line in f_read:
    
                    if ttt in line:
                        f_write.write(ccc+'
    ')
                        continue
                    f_write.write(line)
            if url == 'q':
                exit()
    def tell_msg():
        print("""
           ********************
            删除 : delect
            查找 : select
            增加 : insert
            改变 : change
           ********************
        """ )
    msg = {
        'delect':delect,
        'select':select,
        'insert':insert,
        'change':change
    }
    def main():
        tell_msg()
        m = input('please input your choice:')
        msg[m]()
        if m == 'q':
            exit()
    main()
  • 相关阅读:
    IIS 添加二级应用程序
    VS中发布并调试IIS程序
    未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker
    Flash基础开发习惯指要
    2012云计算扫盲
    flash问题集锦(新手必看)
    Flash常用ActionScript控制语句基本用法祥解
    通过offset值的设置使html元素对齐
    不用float也可以让div横向显示
    QQ空间里写的开发心得
  • 原文地址:https://www.cnblogs.com/liuguniang/p/6685090.html
Copyright © 2011-2022 走看看