#!/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

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.