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

首頁 > 編程 > Python > 正文

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

2019-11-25 16:06:40
字體:
來源:轉載
供稿:網友

本文實例講述了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)

另外還可參考:bash刪除文件中含"指定內容"的行

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳城县| 敦煌市| 客服| 新源县| 如东县| 色达县| 平乡县| 连平县| 姚安县| 盐山县| 竹溪县| 凤庆县| 南澳县| 沛县| 大庆市| 奉贤区| 铁力市| 应城市| 绵阳市| 台安县| 山阳县| 塔河县| 封丘县| 沙河市| 淮阳县| 彭阳县| 苗栗市| 垣曲县| 孝义市| 平定县| 高雄市| 桃园县| 衡阳市| 岱山县| 香港 | 密云县| 康定县| 民和| 永胜县| 焦作市| 谷城县|