Reputation: 9806
Code:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Build dataset')
parser.add_argument('--do_plot', action="store_true",
help='Plot the images')
args = parser.parse_args()
Error:
$ python make_dataset.py --do_plot True
usage: make_dataset.py [-h] [--do_plot]
make_dataset.py: error: unrecognized arguments: True
Upvotes: 4
Views: 9200
Reputation: 351
Just one of reason (which I faced) and hope my hypothesis helps your problem is that on Ubuntu (on Windows, IDK but it's fine),
When you imported a function from a .py
file (let say A.py
) which having args (people create __main__
to test a feature function, let call A
function ). The .py
importing/using A
could be confusedly parsing arguments because A.py
also parse arguments and so on.
So, you could solve by refactoring, or just (temporarily) comment out them to run first.
Upvotes: -1
Reputation: 33714
You do not need to indicate True as far as I can tell, by just including --do_plot
, it is telling it that you wanted to do plot. And plus, you did not configure it to take any arguments.
In the following line of the source code:
if args.do_plot:
If you actually included --do_plot
in the command lines, it will be evaluated as True, if not, it will be evaluated as False.
Upvotes: 4
Reputation: 77837
The problem is in the specification here:
parser.add_argument('--do_plot', action="store_true",
help='Plot ...')
You've declared do_plot as an option without an argument; the True afterward has no purpose in your argument protocol. This is an option that's off by omission, on when present.
Upvotes: 1
Reputation: 17928
As you've configured it, the --do_plot
option does not take any arguments. A store_true
argument in argparse
indicates that the very presence of the option will automatically store True
in the corresponding variable.
So, to prevent your problem, just stop passing True
to --do_plot
.
Upvotes: 9