Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2881
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <karim.liateni@free.fr> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'args': 0.07; 'dictionary': 0.07; 'command-line': 0.09; 'libs': 0.09; 'namespace': 0.09; 'optparse': 0.09; 'parsing': 0.09; 'tuple': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'argparse': 0.16; 'from:addr:free.fr': 0.16; 'received:212.27': 0.16; 'received:212.27.42': 0.16; 'received:free.fr': 0.16; 'subject:command': 0.16; 'command': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'objects': 0.24; 'equivalent': 0.26; 'object': 0.27; 'thanks': 0.29; 'skip:p 30': 0.29; 'error': 0.29; 'subject:?': 0.29; 'cc:addr:python.org': 0.31; 'etc).': 0.31; 'port.': 0.31; 'language.': 0.31; 'called': 0.32; 'option': 0.33; 'module': 0.33; 'using': 0.34; 'received:192': 0.34; 'received:192.168.0': 0.35; 'there': 0.35; 'header:User-Agent:1': 0.35; 'options,': 0.35; 'subject:use': 0.35; 'hello,': 0.36; 'received:192.168': 0.37; 'but': 0.38; 'used': 0.38; 'how': 0.39; 'would': 0.40; 'simple': 0.60; 'best': 0.60; 'flow': 0.69; 'subject:line': 0.73; 'contains.': 0.84 |
| Date | Fri, 08 Apr 2011 23:58:26 +0200 |
| From | Karim <karim.liateni@free.fr> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 |
| MIME-Version | 1.0 |
| To | markolopa <marko.loparic@gmail.com> |
| Subject | Re: How to use optparse without the command line? |
| References | <531582e4-3eac-4dd6-aa87-17b869cd8f84@w6g2000vbo.googlegroups.com> |
| In-Reply-To | <531582e4-3eac-4dd6-aa87-17b869cd8f84@w6g2000vbo.googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.165.1302299914.9059.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1302299914 news.xs4all.nl 41102 [::ffff:82.94.164.166]:34692 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:2881 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar
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