I'm writing a program that takes two argument (paths) and as an option -l
, witch enables save the log in a log file.
I'm using argparse
and create the following argument:
parser.add_argument('-l', '--logfile',
nargs='?',
const='tranfer.log',
default=False,
help='save log of the transfer')
These are the forms of use:
prog.py path_1 path_2
. Nothing special.prog.py -l filename path_1 path_2
. Save the log infilename
file.prog.py -l path_1 path_2
. Save the log the file by default (say,logfile
).
I have a problem in item 3, because prog.py
takes path_1
as the filename of the log file. The issue was easily fixed puttin -l
option at the end of the line.
prog.py path_1 path_2 -l
But I was wondering if there's a way of tell argparse
to use the last two option as the path files, because I'll be not the only one who use the program.
Path argument were add as follows:
parser.add_argument('left_path',
action='store',
help='first path')
parser.add_argument('right_path',
action='store',
help='second path')