Python deletes a row example containing "specified content" in an object,

Source: Internet
Author: User

Python deletes a row example containing "specified content" in an object,

This example describes how to delete rows with specified content in a file in Python. We will share this with you for your reference. The details are as follows:

#!/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)

You can also refer to bash to delete rows containing "specified content" in a file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.