Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the remaining arguments in argparse

I want to get all the remaining unused arguments at once. How do I do it?

parser.add_argument('-i', action='store', dest='i', default='i.log') parser.add_argument('-o', action='store', dest='o', default='o.log') 
like image 801
ggoha Avatar asked Apr 03 '14 22:04

ggoha


People also ask

What does Argparse return?

Later, calling parse_args() will return an object with two attributes, integers and accumulate . The integers attribute will be a list of one or more ints, and the accumulate attribute will be either the sum() function, if --sum was specified at the command line, or the max() function if it was not.

Why do we use Argparse in Python?

The argparse module in Python helps create a program in a command-line-environment in a way that appears not only easy to code but also improves interaction. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments.

What is dest in Argparse?

The dest attribute of a positional argument equals the first argument given to the add_argument() function. An optional argument's dest attribute equals the first long option string without -- . Any subsequent - in the long option string is converted to _ .


1 Answers

Use parse_known_args():

args, unknownargs = parser.parse_known_args() 
like image 74
Elmar Peise Avatar answered Oct 18 '22 19:10

Elmar Peise