0
#!/usr/bin/python3

import sys

input1 = sys.argv[1]

def print_params(*params):
    print(params)

print_params(input1)

#END#

In the above code how can I call all the command line arguments with the prin_params function without having to code input1, input2, input3, etc... When I'm doing testing liket this I would like to be able to just feed my command line arguments right inow print_params() intread of having to manually code every line. I tried print_params(sys.argv[]) but it did not work

2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by vegaseat
0

Hint ...

import sys

# check if there is a commandline
if len(sys.argv) > 1:
    mylist = []
    # sys.argv[0] is the program filename, slice it off
    for element in sys.argv[1:]:
        mylist.append(element)
else:
    print("usage {} element1 element2 [element3 ...]".format(sys.argv[0]))
    sys.exit(1)

# if the arguments were 1 2 3 4 5
# mylist should be ['1', '2', '3', '4', '5']
print(mylist)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.