Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to use argparse

import argparse

if __name__ == "__main__":
	#add a description
	parser = argparse.ArgumentParser(description="what the program does")

	#add the arguments
	parser.add_argument("arg1", help="advice on arg")
	parser.add_argument("arg2", help="advice on arg")
#						.
# 						.
#   					.
	parser.add_argument("argn", help="advice on arg")

	#this allows you to access the arguments via the object args
	args = parser.parse_args()

	#how to use the arguments
	args.arg1, args.arg2 ... args.argn
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #argparse
ADD COMMENT
Topic
Name
4+2 =