argument problem in optparse

John Machin sjmachin at
Fri Mar 20 23:59:04 CET 2009

On Mar 21, 3:44 am, Qian Xu <quian... at> wrote:
> Hi All,
> I have a problem with OptParse.
> I want to define such an arugument. It can accept additional value or no
> value.
> " --unittest File1,File2"
> " --unittest"
> Is it possible in OptParse? I have tried several combination. But ...

Do you meen the included optparse module, or something else? Case
matters :-)

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: --unittest "File1, File2" --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 mailing list