How to use optparse without the command line?

M

markolopa

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
 
K

Karim

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
Move to the best module on args parsing: argparse it is way, way, way
better no equivalent in any others language.
No tuple when parsing but a simple Namespace objects and very easy to
port. Go have a look in std libs (>=v2.7).

Regards
Karim
 
M

markolopa

Move to the best module on args parsing: argparse it is way, way, way
better no equivalent in any others language.
No tuple when parsing but a simple Namespace objects and very easy to
port. Go have a look in std libs (>=v2.7).

argparse seems great for my needs, in particular because the usage of
namespace objects. Do you know if there is a way to use it with Python
2.6? My colleagues won't accept to upgrade the Python version anytime
soon.

Thanks a lot!
Marko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top