2

I am using argparse to parse input arguments. One of the required ones are files, but I want to change the error message:

x.py: error: the following arguments are required: files

to something else. How to do that? I get how you change message if an optional flag is not supplied, but it does not work for mandatory arguments.

I would also like to change this message:

usage: x.py [-h] files [files ...]

Cheers!

ivanacorovic
  • 2,669
  • 4
  • 30
  • 46
  • It might help if you gave the `argparse` code that you do use, and describe what kind of change you want in the error message. But beyond showing you where, in the code, the message is generated, I probably can't help you much. As for the usage, you can define your own `usage` string in the parser definition. It looks like you have defined 'files' as a `nargs='+'` Action. What's wrong with the default usage? – hpaulj Oct 17 '18 at 05:40

1 Answers1

0

Checkout this question, I think it will get you on the right track.

https://stackoverflow.com/a/16942165

Chad Lowe
  • 721
  • 1
  • 6
  • 12