Get arguments

Returned as a list, index 0 being the path + filename of the python file that has been run

    import sys
    command_line_arguments = sys.argv
    #print("This is the name of the program:", sys.argv[0])
    #print(command_line_arguments)            #E.g. ['C:\\MyFolder\\my_app.py', 'abc', 'xyz]

Get argument and its value

This example forces to lower case, remove .lower() if you don’t want that

    found_it = False
    for argument in command_line_arguments:
        if (argument.lower().find("my_argument_text=") == 0):        #0=does string start with, -1=not found
                found_it = True
                argument_value = argument[argument.lower().index("my_argument_text=")+17:]
                break
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *