How to use optparse without the command line?

Miki Tebeka miki.tebeka at gmail.com
Wed Apr 13 09:38:35 EDT 2011


> 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).
I don't think you can get away from encoding/decoding the option dictionary. You can merge the options from the command line though.
options = {"a" : 1, "b" : 2}
opts, args = parser.parse_args()
options.update(opts.__dict__)

HTH
--
Miki Tebeka <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com




More information about the Python-list mailing list