阻止argparse遍历文件路径 [英] Stop argparse from globbing filepath
问题描述
我正在使用带有以下参数定义的python argparse:
I am using python argparse with the following argument definition:
parser.add_argument('path', nargs=1, help='File path to process')
但是当我输入带有wildcard
参数的命令时,argparse
会遍历所有文件路径并以错误终止.
But when I enter my command with a wildcard
argument, argparse
globs all the file paths and terminates with an error.
我如何获得argparse
不会使文件混乱?
How do I get argparse
not to glob the files?
推荐答案
我如何使argparse不会使文件混乱?
How do I get argparse not to glob the files?
你没有.
您将使外壳停止滑动.
You get the shell to stop globbing.
但是.让我们考虑一下.
However. Let's think for a moment.
您是在代码中这样说
parser.add_argument('path', nargs=1, help='File path to process')
但是您实际上在运行通配符时会提供通配符.
But you are actually providing wild-cards when you run it.
这两个错误之一.要么在运行时停止提供通配符,要么修复argparse以允许多个文件名.
One of those two is wrong. Either stop providing wild-cards at run time or fix argparse to allow multiple filenames.
这篇关于阻止argparse遍历文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!