python3.7 带星号(*)的optionparser输入选项成为文件夹中的文件

python3.7 optionparser input option with asterisk(*) becomes a file in the folder

环境:

python3.7
OptionParser with a option [ add_option('-t', '--target', action='append', dest='targets') ]
OS: 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', 'test']
So I believe this is a 'problem' of system level, and what I want to know is:
is there any way to make logs* be logs* without input logs\* in python?

shell是谁在扩充*。 python 在这里无能为力,因为它永远不知道 log*.

您可以强制 shell 将 * 解释为带有一些引号的文字值:

parser -t "logs*" -t test

这适用于 zsh,对于您的 shell 可能有所不同。