argument problem in optparse
sjmachin at lexicon.net
Fri Mar 20 23:59:04 CET 2009
On Mar 21, 3:44 am, Qian Xu <quian... at stud.tu-ilmenau.de> wrote:
> Hi All,
> I have a problem with OptParse.
> I want to define such an arugument. It can accept additional value or no
> "myscript.py --unittest File1,File2"
> "myscript.py --unittest"
> Is it possible in OptParse? I have tried several combination. But ...
Do you meen the included optparse module, or something else? Case
Do you really want no value (and how would you expect optparse to tell
you it got no value?), or would an empty string suffice?
The following should work on Windows; adjust depending on your shell's
quoting/escaping mechanism for getting an empty string or a string
containing whitespace as exactly 1 arg:
myscript.py --unittest "File1, File2"
myscript.py --unittest ""
command-prompt>python -c "import sys; print sys.argv[1:]" foo "
baa baa" "" zot
['foo', 'baa baa', '', 'zot']
More information about the Python-list