[英]python3.7 optionparser input option with asterisk(*) becomes a file in the folder
python3.7
python3.7
OptionParser with a option [ add_option('-t', '--target', action='append', dest='targets') ]带有选项的 OptionParser [ add_option('-t', '--target', action='append', dest='targets') ]
OS: CentOS7.6操作系统:CentOS7.6
So I am using this option to input a list of targets, and with this command line:
所以我使用这个选项来输入一个目标列表,并使用这个命令行:
parser -t logs* -t test
there's a file "logs.tar.gz" in where I execute this command line, when i print the value of targets, this is what i get:在我执行这个命令行的地方有一个文件“logs.tar.gz”,当我打印目标的值时,这就是我得到的:
['logs.tar.gz', 'test']
So I believe this is a 'problem' of system level, and what I want to know is:所以我认为这是系统级别的“问题”,我想知道的是:
is there any way to makelogs*
belogs*
without inputlogs\*
in python?有什么方法可以在 python 中使
logs*
logs*
成为没有输入logs\*
的日志*?
The shell is who is expanding the *
. shell 是谁在扩展
*
。 There is nothing that python can do here since it never gets to know about the log*
. python 在这里无能为力,因为它永远不会知道
log*
。
You can force your shell to interpret the *
as a literal value with some quoting:您可以强制您的 shell 将
*
解释为带有一些引用的文字值:
parser -t "logs*" -t test
This works in zsh, it might be different for your shell.这适用于 zsh,对于您的 shell 可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.