Custom Usage Message for Python
Spellcrafting in Python is approachable and enjoyable. The library argparse facilitates the parsing of arguments for code destined for wide distribution. Below is an example of basic argparse usage #!/usr/bin/env python3 """ in this example get input from the user and manlipulate it """ from argparse import RawTextHelpFormatter import argparse,sys def get_args (): parser = argparse.ArgumentParser(formatter_class = RawTextHelpFormatter) arg_grp = parser.add_argument_group( 'arguments' ) # add an argument to take an int # set the default to None to check for errors, required arg_grp.add_argument( '-n' ,type = int,default = None) # add a required argument for a string # set the required option to True # this argument has two flags, -s --string arg_grp.add_argument( '-s' , '--string' ,type = str,required = True) # this command loads the args # object with user ...