Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.04; 'subject:Python': 0.06; 'error:': 0.07; 'upgraded': 0.07; 'optparse': 0.09; 'subject:command': 0.09; 'subject:parsing': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; "'set',": 0.16; 'accepts': 0.16; 'fine.': 0.16; 'subject:options': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.18; 'module': 0.19; 'skip:f 30': 0.19; 'feb': 0.22; 'machine': 0.22; 'cc:addr:python.org': 0.22; 'install': 0.23; 'conjunction': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'options': 0.25; 'script': 0.25; 'subject: : ': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'probably': 0.32; 'skip:c 30': 0.32; 'option': 0.32; 'run': 0.32; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; '2.6': 0.36; 'possible': 0.36; 'starting': 0.37; 'machines': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'short': 0.38; 'does': 0.39; '8bit%:6': 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=6VECKXAfAbFyqxi6/AWFj+kv1MOEVO5oO+jK4WtUP5M=; b=ytFqVJ0l0VdvDE0EBhFfHHaZlSFXXCKsZ/+vJ9D+gK9sfBBJyiy1p5eItUtejA0i4E 6BdbXaztlwMp5QrQ3uA4zh9bGlLCqFY6T15zjGAK1OlGkNT2W0Rr4jQA8U3wg+WcadpT 1QEgx97BWCoF8kPgCRje2ggpD/A57GAJRGe83a+X8bKXlFL05ZP7opnZ4yYsQTc/G/YD kI4Qz5P8XZQGON55kRzhZAjobz+Ci2O9pH//6tJ/ISu9mYUsghSrXFmuB7vShT+EGqtj N6rgiYwWDOOd7z9WMgbFnxqckSx7V1mMvBiLZH+7XFsgSVazedpi/mzH1m6hAxknuumm rnTg== MIME-Version: 1.0 X-Received: by 10.112.164.5 with SMTP id ym5mr977284lbb.48.1393407021448; Wed, 26 Feb 2014 01:30:21 -0800 (PST) In-Reply-To: References: Date: Wed, 26 Feb 2014 15:00:21 +0530 Subject: Re: Python : parsing the command line options using optparse From: Ganesh Pal To: Peter Otten <__peter__@web.de> Content-Type: multipart/alternative; boundary=001a11c268188a83d504f34bda8b Cc: python-list@python.org 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: 122 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393407329 news.xs4all.nl 2916 [2001:888:2000:d::a6]:34041 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67086 --001a11c268188a83d504f34bda8b Content-Type: text/plain; charset=ISO-8859-1 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. > >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' Long hand Works ( -- , or double hypen ) fine. C:\Users\bahadg\Desktop>python python-5.py --path=/ifs/1.txt --operation=XOR -- offset=1234 --node=1 --log --fixcrc /ifs/1.txt --001a11c268188a83d504f34bda8b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Tue, Feb 25, 2014 at 9:55 PM, Peter Otten=A0<__peter_= _@web.de>=A0wrote:

>As you are just sta= rting I recommend that you use argparse instead of =A0optparse.

=A0I would love to use argparse but =A0the script that = I plan to write has to run on host machines that Python 2.6

<= /div>
=A0I have freebsd clients =A0with python =A02.6 =A0dont want to i= nstall 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 a= nd is it possible to add =A0something like =A0 #pkg_add -r=A0install python-argparse a= nd install python argparse module before I use it.
=


=A0
>If you are asking why short options don't work in c= onjunction with =3D -- I
>don't know, it is probably a desi= gn choice of the optparse author.
>argparse accepts short options wit= h like -f=3D1234


=A0I = wanted to know why my sample program does not work =A0with short hand optio= n (-p) and works with long hand option .

Here is w= hat is happening ( only short hand with -)

# python-5.py -p=3D/ifs/1.txt -q=3DXOR=A0 -f=3D1234 -= n=3D1 -l

Usage: python-5.py [options]

python-5.py: error: option -q: invalid ch= oice: '=3DXOR' (choose from 'XOR', 'ADD',

=A0'SET', 'MODIFY', 'RENAME', 'DELETE', = 9;KILL')


Result :says =A0invalid choice: '=3DXOR'



=A0

Long hand Works ( -- , or double hypen ) fine.

C:\Users\bahad= g\Desktop>python python-5.py --path=3D/ifs/1.txt --operation=3DXOR=A0 --=

offset=3D1234 --node=3D1 --log --fixcrc

/ifs/1.txt

=A0



--001a11c268188a83d504f34bda8b--