Reputation: 45
Below is a snippet of my code in which I am trying to do a sanity check against user's command-line arguments.
My program should accept only two arguments from the user; beside the program name; or otherwise it will spit out a USAGE message for program's usage.
The issue is I can't figure out why the program won't proceed when it is supplied with the desired number of arguments?!
The code keeps returning back the Usage Message no matter how many arguments out there; even when its true to have two of them; any thought about what should I do?
## Perfome a sanity check against command-line arguments
for arg in sys.argv:
if len(arg) != 3:
print(f'Usage: dna.py <DNA database CSV file> <STR sequence text file>')
sys.exit(1)
Upvotes: 0
Views: 479
Reputation: 186
I assume the for loop is not necessary you just need something like this:
if len(sys.argv) != 3:
print("Your usage")
You can always use argparse
standard module, which helps you to build a user-friendly command line program.
Upvotes: 2