python指令碼傳引數argv

perfychi發表於2012-11-25
#diff.py
#!/bin/env python

import sys
if len(sys.argv) <> 3:
    print "Usage: " + sys.argv[0] + "file1 file2"
    sys.exit(-1)

file1 = sys.argv[1]
file2 = sys.argv[2]

list1 = {}
for line in open(file1):
    list1[line.split()[0]] = 1

for line in open(file2):
    key = line.split()[0]
    if key not in list1:
        sys.stdout.write(line)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-749912/,如需轉載,請註明出處,否則將追究法律責任。

相關文章