从通配文件路径中停止 argparse [英] Stop argparse from globbing filepath

查看:19
本文介绍了从通配文件路径中停止 argparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有以下参数定义的 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 不去 glob 文件?

How do I get argparse not to glob the files?

推荐答案

如何让 argparse 不将文件全局化?

How do I get argparse not to glob the files?

你没有.

你让 shell 停止 globbing.

You get the shell to stop globbing.

不过.让我们想一想.

您在代码中这么说

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆