i have a script which take hh:mm:ss inputs
for example
vid_cut.py -t 00:00:30 00:10:00
but when i do
from sys import argv
from argparse import ArgumentParser as AP
ap = AP()
ap.add_argument('-f',type=str)
ap.add_argument('-tp',nargs='+',type=str)
arg = ap.parse_args(argv)
print arg['-tp']
i got
vid_cut.py: error: unrecognized arguments: vid_cut.py
how can I make argparse understand my inputs?
updates
I have now solved the problem, with the following code
# imports
from os import system as sc
from sys import argv
from argparse import ArgumentParser as AP
from itertools import tee , izip
# cmd synthesis
ap = AP()
ap.add_argument('-f',type=str)
#ap.add_argument('-tp',nargs='+',type=str)
ap.add_argument('-tp',nargs='+',type=str)
arg = vars(ap.parse_args())
print argv
print arg
f_name = arg['f']
tp = map(HMS_S, arg['tp'])
ffmpeg_cmd = "ffmpeg -sameq -ss %s -t %s -i %s %s"
# system call
for t,dt in diff(tp):
print ffmpeg_cmd % (t,dt,f_name,f_name + str(t))
the only question is I don’t know why when do we need to do
arg = vars(ap.parse_args(something))
it seems argv has been magically processed.
answer: argv[1:] will be automatically processed, unless you have other stuff to parse.
Since you haven’t given very much code I’ll show an example that will work:
If run with “-t 00:00:30 00:10:00” as arguments then I get this value back: