Stop argparse from globbing file area

I am using python argparse with the following argument definition:

parser.add_argument('path', nargs=1, help='File path to process')

But when I enter my command with an argument wildcard, it argparseswallows all the file paths and completes the error.

How do I get argparsenon glob files?

+5
source share
3 answers

How can I make argparse not swallow files?

No.

You get a shell to stop swallowing.

However. Think for a moment.

You say it in your code

parser.add_argument('path', nargs=1, help='File path to process')

But you do provide wild-cards at startup.

One of these two is incorrect. Either stop providing wildcards at runtime, or fix argparse to resolve multiple file names.

+7

, argparse . , .

glob.glob.

+6

The globe is executed by your shell, not the argparse module. type sys.argvat the beginning and you will see what argparse gets as input.

+4
source

All Articles