def delete(ps):
import os
filename = ps[-]
delelemetns = ps[]
with open(filename, encoding='utf-8') as f_read,\
open('tmp.txt', 'w', encoding='utf-8') as f_write:
for line in iter(f_read.readline, ''):
if line != '\n': # 处理非空行
if delelemetns in line:
line = line.replace(delelemetns,'')
f_write.write(line)
os.remove(filename)
os.rename('tmp.txt',filename) def add(ps):
filename = ps[-]
addelemetns = ps[]
with open(filename, 'a', encoding='utf-8') as fp:
fp.write("\n", addelemetns) def modify(ps):
import os
filename = ps[-]
modify_elemetns = ps[]
with open(filename, encoding='utf-8') as f_read, \
open('tmp.txt', 'w', encoding='utf-8') as f_write:
for line in iter(f_read.readline, ''):
if line != '\n': # 处理非空行
if modify_elemetns in line:
line = line.replace(modify_elemetns, '')
f_write.write(line)
os.remove(filename)
os.rename('tmp.txt', filename) def search(cmd):
filename = cmd[-]
pattern = cmd[]
with open(filename, 'r', encoding="utf-8") as f:
for line in f:
if pattern in line:
print(line, end="")
else:
print("没有找到") dic_func ={'delete': delete, 'add': add, 'modify': modify, 'search': search} while True:
inp = input("请输入您要进行的操作:").strip()
if not inp:
continue
cmd_1 = inp.split()
cmd = cmd_1[]
if cmd in dic_func:
dic_func[cmd](cmd_1)
else:
print("Error")

yyy的更多相关文章

  1. Flash Professional 报错 TypeError: Error #1034: 强制转换类型失败:无法将 xxxx@zzzz 转换为 yyy

    通常是因为xxx yyy 两个不同链接名的元件 使用了同一个属性名

  2. java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题

    File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 j ...

  3. 洛谷 P1803 凌乱的yyy Label:Water 贪心

    题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的. yyy认为,参加越多的比赛,noip就能考的越好(假的) 所以,他想知道他最多能参加 ...

  4. 凌乱的yyy

    题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的. yyy认为,参加越多的比赛,noip就能考的越好(假的) 所以,他想知道他最多能参加 ...

  5. wget https://github.com/xxx/yyy/archive/${commit_hash}.zip

    wget https://github.com/xxx/yyy/archive/${commit_hash}.zip

  6. svn:Repository UUID 'XXX' doesn't match expected UUID 'YYY'

    About a month ago, CodePlex have upgraded their TFS servers to to TFS 2010. While this transition wa ...

  7. Struts2中DMI(动态方法调用)的错误问题(There is no Action mapped for namespace [/xxx] and action name [xxx!yyy] a)

    默认的Struts.xml中是这样的 <constant name="struts.enable.DynamicMethodInvocation" value="f ...

  8. [洛谷1580]yyy loves Easter_Egg I

    题目背景 Soha的出题效率着实让人大吃一惊.OI,数学,化学的题目都出好了,物理的题还没有一道.于是,Huntfire,absi2011,lanlan对soha进行轮番炸,准备炸到soha出来,不料 ...

  9. [洛谷2397]yyy loves Maths VI

    题目背景 自动上次redbag用加法好好的刁难过了yyy同学以后,yyy十分愤怒.他还击给了redbag一题,但是这题他惊讶的发现自己居然也不会,所以只好找你 题目描述 他让redbag找众数他还特意 ...

  10. 在PHP网页中,如何把$_session["yyy"]赋值到一个文本框中?

    echo '<input type="text" id="text1" name="text1" value="'.$_SE ...

随机推荐

  1. Oracle.EntityFrameworkCore使用时报错:ORA-00933:SQL命令未正确结束

    如果你在使用 Oracle.EntityFrameworkCore 在执行一些分页查询或者其他数据操作时,遇到“ORA-00933:SQL命令未正确结束”, 请先检查你的DbContext中UseOr ...

  2. Eclipse开发环境(一):下载和安装

    一.Eclipse下载及安装 1. 下载 进入官网https://www.eclipse.org/,点击 IDE & Tools 选择Java EE 选择Luna Packages 选择Win ...

  3. python PIL图像处理库

    1. Introduction PIL(Python Image Library)是python的第三方图像处理库,但是由于其强大的功能与众多的使用人数,几乎已经被认为是python官方图像处理库了. ...

  4. python 爬虫 user-agent 生成

    有些网站做了反爬技术,如:比较初级的通过判断请求头部中的user-agent字段来检测是否通过浏览器访问的. 在爬这类网站时需要模拟user-agent import random import re ...

  5. SAP云平台CloudFoundry环境里route 超过quota的错误处理

    试图往SAP Cloud Platform CloudFoundry用命令行CLI部署应用时,遇到如下错误: 原因是因为这个新建的名为Haytham的subaccount没有分配application ...

  6. unity获取ugui上鼠标位置

    public class GetMousePos : MonoBehaviour { public Canvas canvas;//画布 private RectTransform rectTrans ...

  7. with读、写文件

    1.with写文件 save_file = "1.txt" str_data = "123a\nbc" with open(save_file, 'a', en ...

  8. JavaScript: 自动类型转换

    我们都知道,JavaScript是类型松散型语言,在声明一个变量时,我们是无法明确声明其类型的,变量的类型是根据其实际值来决定的,而且在运行期间,我们可以随时改变这个变量的值和类型,另外,变量在运行期 ...

  9. ubuntu下关于profile和bashrc中环境变量的理解(转)

    ubuntu下关于profile和bashrc中环境变量的理解(转)   (0) 写在前面 有些名词可能需要解释一下.(也可以先不看这一节,在后面看到有疑惑再上来看相关解释) $PS1和交互式运行(r ...

  10. mysqldump 全备

    [root@db01 b]#mysqldump -uroot -poldboy123 -A -R --triggers --master-data=2 --single-transaction | g ...