Python argparse argument with quotes

denvaar picture denvaar · Nov 1, 2012 · Viewed 10.4k times · Source

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"

Answer

wim picture wim · Nov 1, 2012

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