删除txt文件里的 聊天记录的时间那一行 f = open("d:\\面试.txt", "r") g = open("d:\\英雄联盟ADC技巧.txt", "w") for line in f.readlines(): if "21:" not in line: g.write(line) f.close() g.close()…
#!/usr/bin/python num=0; ni=open("C:\Python34\ceshi.txt") for line in ni: num=num+1; #表示行数 if num==4: #当num为4时,打印出第四行的内容,在开始的编写中写成了num=4,运行时一直提示语法错误,找了半天原因才明白需写成==,=是赋值,==是比较 print(line) ni.close() #import linecache #print(linecache.getline(…
代码如下: import shutil readPath='E:/word4.txt' #要处理的文件 writePath='E:/word5.txt' #要写入的文件 lines_seen=set() outfiile=open(writePath,'a+',encoding='utf-8') f=open(readPath,'r',encoding='utf-8') for line in f: if line not in lines_seen: outfiile.write(line)…