I have a Python file with several function definitions in it. One of the functions, named 'main' will be called as soon as the Python file is run.
myFile.py import sys def main(arg1....): ---code--- --more functions-- main()
When a person wants to run my file they'll type:
python myFile.py arg1 arg2 ...
The main function is supposed to accept in x number of arguments, however, in case the user doesn't wish to pass in any arguments we're supposed to have default values.
My program looks something like this and I'm hoping there is actually a better way to do this than what I have:
myFile.py import sys #Even though my function has default values, if the user doesn't wish #to input in any parameter values, they still must pass in the word False #otherwise, pls pass in parameter value def main(name = "Bill", age = 22, num_pets=5, hobby = "soccer"): if len(sys) > 1: i =0 while i < len(sys): if i == 0: if sys.argv[i] == "False": i += 1 continue else: name = sys.argv[i] i += 1 continue elif i == 1: if sys.argv[i] == "False": --------etc. etc.-----------