Read file - Posted on July Mon 19th 3:21 AM (Never Expires) - Format: python
  1. #!/usr/bin/python
  2. from csv import reader
  3. import csv,re, sys, getopt
  4.  
  5. def main(argv):
  6.     inputfile = ''
  7.     outputfile = ''
  8.     try:
  9.         opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
  10.     except getopt.GetoptError:
  11.         print 'convert.py -i <inputfile> -o <outputfile>'
  12.         sys.exit(2)
  13.     for opt, arg in opts:
  14.         if opt == '-h':
  15.             print 'convert.py -i <inputfile> -o <outputfile>'
  16.             sys.exit()
  17.         elif opt in ("-i", "--ifile"):
  18.             inputfile = arg
  19.         elif opt in ("-o", "--ofile"):
  20.             outputfile = arg
  21.     print 'Input file is ', inputfile
  22.     print 'Output file is ', outputfile
  23.     regex = re.compile(r"\s*\b(?!href|src)[^\s]+=\"[^\"]*\"(?=[^<>]*>)", re.IGNORECASE)
  24.     with open(inputfile, 'r') as read_obj, open(outputfile, 'wb') as write_obj:
  25.         csv_reader = reader(read_obj,  quoting=csv.QUOTE_MINIMAL,  delimiter=',', quotechar='"', skipinitialspace=True, lineterminator = '\r\n')
  26.         writer = csv.writer(write_obj, quoting=csv.QUOTE_NONNUMERIC,  delimiter=',', quotechar='"', skipinitialspace=True)
  27.         for row in csv_reader:
  28.             row.append(regex.sub(r"", row[2]))
  29.             writer.writerow(row)
  30.  
  31. if __name__ == "__main__":
  32.    main(sys.argv[1:])

New Paste

Paste Options

Recent Pastes

42 days ago

FACEBOOK LINKEDI

46 days ago

BUSINESS DATABAS

138 days ago

Untitled

146 days ago

Untitled

146 days ago

Untitled

146 days ago

Untitled

146 days ago

Untitled

146 days ago

Untitled

146 days ago

Untitled

496 days ago

Read file