What I am doing now is to simply check for args length, if it is 0, tell user to type -h.
Is there a better way to do this ?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s not clear from your question whether you are using the (deprecated) optparse module or its replacement, the argparse module. Assuming the latter, then as long as you have at least one positional argument your script will print out a usage message if no arguments (or insufficient arguments) are supplied.
Here’s an example script:
If I run this with no arguments, I get this result: