I wrote a Python script that I am now trying to get to run via the command line. It consists of a function that takes one obligatory and a few optional arguments.
def main(input_folder, iterations = 1000, probability_cutoff = - 40 , threshold = 10): ...
Now I am trying to make it executable through the command line like so:
if __name__ == "__main__":
main(sys.argv[1])
This works well as long as I put in only one argument; but I don't know how to accept the additional, optional input that sys.argv
delivers as a list.
- Is there a simple way of doing this with this approach?
- Or is it necessary to use an additional module such as argparse?
- I tried feeding keyword arguments into the function as well but couldn't make that work either - is that a feasible approach?
I am working with Python 2.7 on a Mac. Any help is much appreciated!