国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現刪除文件中含“指定內容”的行示例

2020-01-04 17:18:23
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現刪除文件中含指定內容的行。分享給大家供大家參考,具體如下:

#!/bin/env pythonimport shutil, sys, osdarray = [  "Entering directory",  "In function ",  "Leaving directory",  "__NR_SYSCALL_BASE",  "arm-hisiv100-linux-ar ",  "arm-hisiv100-linux-gcc ",  "but argument is of type",  "dereferencing type-punned pointer will break strict-aliasing rules",  "differ in signedness",  "does break strict-aliasing rules",  "embedded '//0' in format",  "excess elements in array initializer",  "implicit declaration of",  "make -C ",  " rm -f",  "this is the location of the previous definition",  "warning: multi-line comment"]def isInArray (array, line):  for item in array:    if item in line:      return True  return Falseif __name__ == '__main__':  argv = sys.argv  argc = len(argv)  if argc < 2:    print "Usage: %s <file>" %(os.path.basename(argv[0]))    exit()  fname = argv[1]  fresult = fname + ".result"  with open(fname, 'r') as f:    with open(fresult, 'w') as g:      for line in f.readlines():        if not isInArray(darray, line):          g.write(line)

 

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊宁县| 怀集县| 西青区| 公主岭市| 金堂县| 安阳市| 扎赉特旗| 嘉峪关市| 通山县| 南溪县| 恭城| 疏附县| 黄平县| 东兴市| 离岛区| 伽师县| 布拖县| 苍溪县| 莱西市| 甘孜| 育儿| 通化县| 松原市| 绩溪县| 涿州市| 南涧| 永登县| 云南省| 蚌埠市| 稻城县| 伊通| 湾仔区| 洛浦县| 沙坪坝区| 合阳县| 南昌市| 浦城县| 股票| 石家庄市| 阳西县| 奉化市|