I wrote a function in python which takes 2 lists (with the same length) and returns another list with 2 elements. the function works perfectly but I am trying to run the python script in command line. to do so, I want to use argparse module in python. I wrote the following script in python3 using the following command:
python3 text.py a b results
the script should take 3 arguments 2 lists as input and one list as output. here is the script:
def fun(a, b):
a_is_greater = 0
b_is_greater = 0
for element_a, element_b in zip(a, b):
if element_a > element_b:
a_is_greater += 1
elif element_a < element_b:
b_is_greater += 1
return [a_is_greater, b_is_greater]
def main():
import argparse
ap = argparse.ArgumentParser(description="")
ap.add_argument('--list-type', type=list)
ap.add_argument('--list-type', type=list)
ap.add_argument('-o', '--outlist', required=True)
args = ap.parse_args()
results = fun(a, b)
return results
if __name__ == "__main__":
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
try:
main()
except IOError as e:
if e.errno != 32:
raise
except KeyboardInterrupt as e:
pass
do you know how to fix it? I have tried these 2 lists: a = [4, 5, 2] and b = [3, 5, 4]. fun function in the script works perfectly for these 2 inputs.