1) The way you define --same
and --diff
they require an argument to follow them that would be assigned to the parsed arguments namespace. To make them boolean flags instead, you change that action by specifying the keyword argument action='store_true'
:
parser.add_argument('--same',
help='Find those in List1 that are the same in List2',
action='store_true')
2) You don't store the parsed arguments in a variable, and you're trying to refer to them as locals instead of on the object returned by parse_args()
:
args = parser.parse_args()
if args.same:
# ...
3) If you specify type=file
for the argument, the parsed argument will actually already be an opened file object - so don't use open()
on it:
data1 = set(l.rstrip() for l in args.infile1)
Note: Currently a user can legally specify both --same
and --diff
, so your program needs to deal with that. You'll probably want to make those flags mutually exclusive.