import argparse
def main():
# Create the parser
= argparse.ArgumentParser(description="Example script.")
parser
# Add arguments with both short and long options
'-a1', '--arg1', type=str, required=True, help="First argument (string).")
parser.add_argument('-a2', '--arg2', type=int, required=True, help="Second argument (integer).")
parser.add_argument(
# Parse the arguments
= parser.parse_args()
args
# Use the arguments
print(f"arg1: {args.arg1}")
print(f"arg2: {args.arg2}")
if __name__ == "__main__":
main()
Parser example
Usage in bash: python parser_example.py -a1 "hello" -a2 42