最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)刪除文件中含“指定內(nèi)容”的行示例

 更新時(shí)間:2017年06月09日 09:25:30   作者:JoeBlackzqq  
這篇文章主要介紹了Python實(shí)現(xiàn)刪除文件中含“指定內(nèi)容”的行功能,涉及Python針對(duì)文件讀取及字符串遍歷、判斷等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)刪除文件中含指定內(nèi)容的行。分享給大家供大家參考,具體如下:

#!/bin/env python
import shutil, sys, os
darray = [
  "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 False
if __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刪除文件中含"指定內(nèi)容"的行

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

巴东县| 格尔木市| 搜索| 同心县| 临西县| 阿尔山市| 米脂县| 新竹县| 龙胜| 宁都县| 龙门县| 东乡| 金湖县| 漳州市| 太和县| 祥云县| 安福县| 民乐县| 乐山市| 丰台区| 武邑县| 莒南县| 铜山县| 兴山县| 襄城县| 洛扎县| 定南县| 苏州市| 长宁区| 图们市| 乃东县| 日土县| 襄樊市| 海宁市| 观塘区| 正蓝旗| 平乡县| 罗甸县| 德惠市| 深水埗区| 临洮县|