Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

argparse type

parser.add_argument("arg1", type=int)
Comment

PREVIOUS NEXT
Code Example
Python :: how add a favicon to django 
Python :: python string contains substring ignore case 
Python :: delete from table django 
Python :: remove key from dictionary python 
Python :: convert method to str python 
Python :: python singleton class 
Python :: break input loop 
Python :: github3 python 
Python :: for loop python 
Python :: python skip line 
Python :: tree in python 
Python :: numpy.where 
Python :: flask flash The browser (or proxy) sent a request that this server could not understand. 
Python :: check if value is in series pandas 
Python :: are logN and (lognN) same 
Python :: How to clone or copy a list in python 
Python :: how to create a new dataframe in python 
Python :: how to normalize scipy cross correlation 
Python :: gui button in tkinter color 
Python :: Percent to number python 
Python :: replace by positions a string in a list with another string python 
Python :: define a function in python without arguments 
Python :: append element to list py 
Python :: nested list comprehension python 
Python :: cool python imports 
Python :: python test framework 
Python :: if or python 
Python :: has no attribute pythin 
Python :: how to return the sum of two numbers python 
Python :: NaN stand for python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =