Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2762 > unrolled thread

How to use optparse without the command line?

Started bymarkolopa <marko.loparic@gmail.com>
First post2011-04-07 01:37 -0700
Last post2011-04-13 06:18 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to use optparse without the command line? markolopa <marko.loparic@gmail.com> - 2011-04-07 01:37 -0700
    Re: How to use optparse without the command line? Karim <karim.liateni@free.fr> - 2011-04-08 23:58 +0200
      Re: How to use optparse without the command line? markolopa <marko.loparic@gmail.com> - 2011-04-13 06:18 -0700

#2762 — How to use optparse without the command line?

Frommarkolopa <marko.loparic@gmail.com>
Date2011-04-07 01:37 -0700
SubjectHow to use optparse without the command line?
Message-ID<531582e4-3eac-4dd6-aa87-17b869cd8f84@w6g2000vbo.googlegroups.com>
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

[toc] | [next] | [standalone]


#2881

FromKarim <karim.liateni@free.fr>
Date2011-04-08 23:58 +0200
Message-ID<mailman.165.1302299914.9059.python-list@python.org>
In reply to#2762
On 04/07/2011 10:37 AM, markolopa wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#3125

Frommarkolopa <marko.loparic@gmail.com>
Date2011-04-13 06:18 -0700
Message-ID<1969ff17-b43c-4552-bb0a-93287571cceb@r14g2000vbm.googlegroups.com>
In reply to#2881
On Apr 8, 11:58 pm, Karim <karim.liat...@free.fr> wrote:
> On 04/07/2011 10:37 AM, markolopa wrote:
>
> > Is there support/idioms/suggestions for usingoptparsewithout a
> >commandline?
>
> > I have a code which used to be called through subprocess. The whole
> > flow of the code is based on what 'options' object fromoptparse
> > 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
> >optparseand benefiting from its option management (check, error
> > detection, etc).
>
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web