Created
March 18, 2015 16:03
-
-
Save Newky/848d658aa09295bd4759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import contextlib | |
""" | |
Example usage: | |
python2.7 distinct_files.py --fileA=<fileA> --fileB=<fileB> > filenames_in_fileA_not_in_fileB.txt | |
""" | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--fileA", dest="fileA", type=argparse.FileType('r')) | |
parser.add_argument("--fileB", dest="fileB", type=argparse.FileType('r')) | |
args = parser.parse_args() | |
with contextlib.closing(args.fileA), contextlib.closing(args.fileB): | |
filenames_a = set([ | |
line.strip() for line in args.fileA.readlines() | |
]) | |
filenames_b = set([ | |
line.strip() for line in args.fileB.readlines() | |
]) | |
distinct_a = filenames_a - filenames_b | |
for filename in distinct_a: | |
print filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment