Make python display help screen if no action is given

Posted by luckytaxi on Stack Overflow See other posts from Stack Overflow or by luckytaxi
Published on 2011-01-14T16:49:37Z Indexed on 2011/01/14 16:53 UTC
Read the original article Hit count: 189

Filed under:

Let's say a user runs the script w/o giving any paramters. How can I make it so that it defaults to ./myscript.py -h so that it shows them the help info?

parser = optparse.OptionParser()

parser.add_option("-d", "--directory", metavar="DIR",
                    help="Directory to scan for big files")
parser.add_option("-e", "--email", metavar='EMAIL', 
                    help='email to send the list to')
parser.add_option("-l", "--limit", metavar='LIMIT', 
                    help='return number of files')

© Stack Overflow or respective owner

Related posts about python