04-09,Work-对文件的增删改查(函数)

#增删改查之查def look():    while 1 :        enter = input("查看:如www.oldboy.org\n")        l = []        flag = False        with open("haproxy.conf") as enter_read:            for line in enter_read:                if line.startswith("backend") and enter in line:                    flag = True                    continue                if line.startswith("backend") and flag:                    break                if flag:                    l.append(line.strip())            for out in l:                print(out)#增删改查之删def delete():    dels = input("删除:如www.oldboy.org\n")    with open("haproxy.conf") as dels_read,open("text",mode="w") as dels_del:        for line in dels_read:            dels_del.write(line)            if line.startswith("backend") and dels in line:                break#增删改查之改def amend():    modify = input("修改:如www.oldboy.org\n")    servers = "        server 1111 weight 2222 maxconn 3333"    with open("haproxy.conf") as modify_read,open("text",mode="w") as modify_m:        for line in modify_read:            modify_m.write(line)            if line.startswith("backend") and modify in line:                modify_m.write(servers)                break#增删改查之增def add():    agg = input("增加:如www.oldboy.org\n")    servers = "        server 1111 weight 2222 maxconn 3333\n"    with open("haproxy.conf") as agg_read, open("text", mode="w") as agg_a:        for line in agg_read:            agg_a.write(line)            if line.startswith("backend") and agg in line:                agg_a.write(servers)

#列表def  list():    user_list = ‘‘‘        1.look 查看:        2.delete 删除:        3.amend 修改:        4.add 增加:        0.exit 退出:        ‘‘‘    print(user_list)

def mains():    list()    judge = input("弄什么:")    if judge==1:        look()    if judge==2:        delete()    if judge==3:        amend()    if judge==4:        add()    if judge==0:        exit()mains()
时间: 2024-08-11 01:33:44

04-09,Work-对文件的增删改查(函数)的相关文章

MyBatis学习(二)、SQL语句映射文件(2)增删改查、参数、缓存

二.SQL语句映射文件(2)增删改查.参数.缓存 2.2 select 一个select 元素非常简单.例如: Xml代码   <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String" resultMap="studentResultMap"> SELECT ST.STUDENT_ID, ST.STUDENT_NAME, ST.STUDENT_SEX

文件的增删改查

有以下员工信息表 当然此表你在文件存储时可以这样表示 1 1,Alex Li,22,13651054608,IT,2013-04-01 现需要对这个员工信息文件,实现增删改查操作 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 select  * from staff_table where dept = "IT" select  * from staff_table where enroll

Python基础-----实现文件的增删改查

实现文件的增删改查 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import os 4 def file_handler(backend_data,res = None,type = 'fetch'): #文件处理函数 5 if type == 'fetch': #查询操作 6 with open('haproxy.conf','r') as read_f: 7 tag = False #初始状态标识 8 ret = [] #用于放置查询

对*.ini文件的增删改查

文件的格式有很多种 *.ini 一般是带一个齿轮的配置文件,这个文件的操作有专门的类库进行处理不行自己硬编码      ini4j.jar 这个jar包专门封装了处理*.ini文件的方法. 1 public interface IParaManager { 2 public int getKey(String section, String key, CInt value); 3 public int getkey(String section, String key, CString valu

Python 模拟SQL对文件进行增删改查

1 #!/usr/bin/env python 2 # _*_ coding:UTF-8 _*_ 3 # __auth__: Dalhhin 4 # Python 3.5.2,Pycharm 2016.3.2 5 # 2017/05/15 6 7 import sys,os 8 9 def where(dbfile,where_list): #条件是一个list 10 11 def and_or_where(sub_where_list): 12 '''获取and或同时含有and.or关键字的条

对文件的增删改查 以及 ---三次登陆

文件 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 a

Day5.对文件的增删改查+三次登陆后锁定

作业1:对文件haproxy.conf进行增删改查: haproxy.conf原文件内容如下: 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 stat

常用的增删改查函数

无论做什么系统,涉及到数据库肯定离不开增删改查,下面是自己写的有关数据库增删改查封装的函数,仅供参考. using System; using System.ComponentModel; using System.Collections; using System.Diagnostics; using System.Data; using System.Data.SqlClient; using System.Configuration; using OnLineExam.HelperClas

python文件的增删改查操作

1 def choice(): 2 print(''' 3 1 查找 4 2 删除 5 3 添加 6 4 修改 7 ''') 8 def forlist(): 9 with open("test2", encoding="utf8", mode="r+") as w: 10 for line in w: 11 print(line.strip()) 12 13 14 def check(): 15 usr=input("输入你要查找的域