带引号的 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"
推荐答案
我认为是shell吃掉了它们,所以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屋!