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


Groups > comp.lang.python > #2881

Re: How to use optparse without the command line?

Date 2011-04-08 23:58 +0200
From Karim <karim.liateni@free.fr>
Subject Re: How to use optparse without the command line?
References <531582e4-3eac-4dd6-aa87-17b869cd8f84@w6g2000vbo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.165.1302299914.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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

csiph-web