Python argparse argument with quotes

柔情痞子 提交于 2019-12-19 05:53:34

问题


Is there any way I can tell argparse to not eat quotation marks?

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"

produces

interactive-00

I want

"interactive-00"

回答1:


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.

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"'


来源:https://stackoverflow.com/questions/13168666/python-argparse-argument-with-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!