带有引号的Python argparse参数 [英] Python argparse argument with quotes
问题描述
有什么办法可以告诉argparse不要吃引号吗?
Is there any way I can tell argparse to not eat quotation marks?
例如,当我给引号加引号时,argparse仅将引号内的内容作为引数.我也想捕获引号(而不必在命令行中将其转义.)
For example, When I give an argument with quotes, argparse only takes what's inside of the quotes as the argument. I want to capture the quotation marks as well (without having to escape them on the command line.)
pbsnodes -x | xmlparse -t "interactive-00"
产生
interactive-00
我想要
"interactive-00"
推荐答案
我认为是吃它们的外壳,所以python实际上永远看不到它们.在命令行上转义它们可能是您唯一的选择.
I think it is the shell that eats them, so python will actually never see them. Escaping them on the command line may be your only option.
如果是出于某种原因而使您不喜欢的\"backslash\"
样式,那么这种方法应该可以代替:
If it's the \"backslash\"
style escaping you don't like for some reason, then this way should work instead:
pbsnodes -x | xmlparse -t '"interactive-00"'
这篇关于带有引号的Python argparse参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!