Passing empty string to argparse
argparse, command-line, python, python-3.2
Solution
This seems to work for me under OS-X:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--mode')
p = parser.parse_args()
print(p)
and then:
python test.py --mode=
I don't have a windows machine, so I don't know anything about how those operate...
Of course, the other things you mentioned above would work as well on OS-X. The advantage here is that it shouldn't rely on how the shell splits arguments enclosed in quotations which should make it work in more places I would think.
Problem
I'm using `argparse` (Python 3.2). A parameter `mode` is defined simply as: ``` p.add_argument('--mode', dest='mode') ``` I want to call the program from the command line in such a way that parameter `mode` is set to an empty string; or at least to a single space `' '` (I can strip whitespace later). I tried to use (under Windows) `program_name --mode ""` and `program_name --mode " "`, but neither worked.