ex:
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 ...
My question:
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.-----------
Is there a better way to do this?
Thank you in advance
This post has been edited by atraub: 19 December 2012 - 02:26 PM

New Topic/Question
This topic is locked



MultiQuote






|