python arg parse

chwma@chwma-PC:~/log_process$ cat merge_key.py
#!/usr/bin/python2

import argparse

def ReadFile(filename):
  line_set = set()
  fp = open(filename, "r")
  lines = fp.readlines()
  for line in lines:
    line_set.add(line)
  return line_set


def merge_key(inputfile, outputfile):
  set1 = ReadFile(inputfile)
  stmp = ReadFile("pairs")
  set2 = set()
  for line in stmp:
    tmp = line.split('\t')[0]+'\n'
    set2.add(tmp)
  print len(set1)
  print len(set2)

  set3 = set1 & set2
  print len(set3)

  f3 = file(outputfile,"w+")
  f3.writelines(set3)

def ParseManager():
  parse = argparse.ArgumentParser(description = "input and output file")
  parse.add_argument('--ifile', '-i', required = True, help = "input file")
  parse.add_argument('--ofile', '-o', required = True, help = "output file")
  args = parse.parse_args()
  return args

def main():
  args = ParseManager()
  merge_key(args.ifile, args.ofile)

if (__name__ == "__main__"):
  main()

python

相關文章
相關標籤/搜索