How to use optparse without the command line?

markolopa marko.loparic at gmail.com
Thu Apr 7 10:37:39 CEST 2011


Hello,

Is there support/idioms/suggestions for using optparse without a
command line?

I have a code which used to be called through subprocess. The whole
flow of the code is based on what 'options' object from optparse
contains.

Now I want to call this code without subprocessing. What I did first
was to build a "fake" command-line and use

options, args = parser.parse_args(fake_cmdline)

But I find it dumb to encode and decode a dictionary... So I would
like to know how I if there is a good way of passing a dictionary to
optparse and benefiting from its option management (check, error
detection, etc).

Thanks a lot!
Marko



More information about the Python-list mailing list