Python argparse argument with quotes

2019-02-22 11:27发布

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条回答
成全新的幸福
2楼-- · 2019-02-22 11:35

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"'
查看更多
登录 后发表回答