Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'subject:Python': 0.06; 'error:': 0.07; 'upgraded': 0.07; 'optparse': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:command': 0.09; 'subject:parsing': 0.09; 'subject:using': 0.09; 'xor': 0.09; 'python': 0.11; '2.7': 0.14; "'set',": 0.16; 'accepts': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:options': 0.16; 'wrote:': 0.18; 'module': 0.19; 'feb': 0.22; 'machine': 0.22; 'install': 0.23; 'header:User-Agent:1': 0.23; 'conjunction': 0.24; 'stick': 0.24; 'options': 0.25; 'script': 0.25; 'subject: : ': 0.26; 'pass': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'host': 0.29; 'work.': 0.31; '25,': 0.31; 'probably': 0.32; 'option': 0.32; 'run': 0.32; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'add': 0.35; 'version': 0.36; '2.6': 0.36; 'possible': 0.36; 'should': 0.36; 'starting': 0.37; 'machines': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'short': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'eventually': 0.60; 'new': 0.61; 'love': 0.65; 'here': 0.66; 'sample': 0.67; 'dont': 0.67; 'invalid': 0.68; 'hand': 0.80; 'freebsd': 0.84; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Python : parsing the command line options using optparse Date: Wed, 26 Feb 2014 12:27:17 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdbb62.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393414043 news.xs4all.nl 2858 [2001:888:2000:d::a6]:40875 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67090 Ganesh Pal wrote: > On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten <__peter__@web.de> wrote: > >>As you are just starting I recommend that you use argparse instead of > optparse. > > I would love to use argparse but the script that I plan to write has to > run on host machines that Python 2.6 > > I have freebsd clients with python 2.6 dont want to install python new > version on all the host machine which will be eventually upgraded to 2.7 . > > I wanted know if I could use argparse with python 2.6 and is it possible > to > add something like #pkg_add -r install python-argparse and install > python argparse module before I use it. Probably, but I have no experience with freebsd. >> >If you are asking why short options don't work in conjunction with = -- >> >I don't know, it is probably a design choice of the optparse author. >> >argparse accepts short options with like -f=1234 > > I wanted to know why my sample program does not work with short hand > option (-p) and works with long hand option . > > Here is what is happening ( only short hand with -) > > # python-5.py -p=/ifs/1.txt -q=XOR -f=1234 -n=1 -l > > Usage: python-5.py [options] > > python-5.py: error: option -q: invalid choice: '=XOR' (choose from 'XOR', > 'ADD', > > 'SET', 'MODIFY', 'RENAME', 'DELETE', 'KILL') > > > Result :says invalid choice: '=XOR' If you stick with optparse just pass the options without '=' -qXOR and -q XOR should both work.