My Requirement:
For now when I run my python application with this command
python main.py -d listhere/users.txt
The program will run and save the result file as predefined name say reports.txt
Now I want to add this functionality to allow users to choose what to put the filename and where to save as so
python main.py -d -o output/newfilname -i listhere/users.txt
Everything is same but I want another argument -o to be passed which will determine the filpath and name to be saved. How do I do it. What is the best way to handle or combine multiple options.
I tried this
parser = argparse.ArgumentParser(description = "CHECK-ACCESS REPORTING.")
parser.add_argument('--user','-d', nargs='?')
parser.add_argument('--output','-d -o', nargs='?')
parser.add_argument('--input','-i', nargs='?')
args = parser.parse_args(sys.argv[1:])
if args.output and args.input:
#operation that involves output filename too
elif args.user and not args.input:
#default operation only
else:
#notset
I am getting this error when trying to solve the issue this way
Error:
report.py: error: unrecognized arguments: -o listhere/users.txt
-options to another-option, no,-d -ois not a valid option name here. Why not just have a-ooption to specify the output name?python report.py -d -o listhere/users.txt -i list/here.txt-d users.txtand the new-i users.txt? What's the purpose of option-d?