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


Groups > comp.lang.python > #72303

Re: Optparse to parsing Suggestions !!

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ganesh1pal@gmail.com>
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; '"""': 0.07; 'modify': 0.07; 'parser': 0.07; 'args)': 0.09; 'field)': 0.09; 'function:': 0.09; 'line:': 0.09; 'lookup': 0.09; 'optparse': 0.09; 'skip:/ 10': 0.09; 'subject:parsing': 0.09; 'python': 0.11; 'def': 0.12; '#python': 0.16; '8bit%:1': 0.16; 'default:': 0.16; 'main():': 0.16; 'optional': 0.16; 'simulate': 0.16; 'skip:" 70': 0.16; 'skip:" 80': 0.16; 'skip:a 100': 0.16; 'storing': 0.16; 'throw': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'entered': 0.20; 'command': 0.22; 'email addr:gmail.com&gt;': 0.22; 'saying': 0.22; 'error': 0.23; 'parse': 0.24; 'skip:" 30': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'accomplished': 0.31; 'file': 0.32; 'this.': 0.32; 'run': 0.32; 'cases': 0.33; 'fri,': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.35; '8bit%:9': 0.36; 'should': 0.36; 'skip:- 20': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'skip:\xc2 10': 0.60; 'skip:o 30': 0.61; 'choose': 0.64; '8bit%:10': 0.64; '30,': 0.65; 'world': 0.66; 'here': 0.66; 'sample': 0.67; '8bit%:31': 0.68; '\xc2\xa0\xc2\xa0': 0.74; '==&gt;': 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 :content-type; bh=//yF6Mot0n+wU3NuBRma1W2wO40OlvtLzWGEtCBgKg8=; b=IiwSE+gCP48CQl45RQkRpIOX8zigWGOHe9fJwAJu7oNJ/rezDNbh0OD7l57pWQZtgC Y+1dxL58JY5M7kxEXjO5wLyaEk9mrchJgwqY8bQIFT4ibpqwslF4Jnht7UIFGSNsD6sS sTkJcuGNG0PW1kfSkg6EWqwj2M732n8fARWF6IMktKtcH0jSx2VTkp8lhcHQRNYI3yZu ibyxyZsNtybhwITWYj/LqmI+MxiLhSsCj718pFWEHYW3FGo7IlIxZvqwiCr8PTqLLWKJ oLwIuYAhmQCcooAhLKdRE2vaHeESy+W2CBM6GggihXH0KTjeJDipeUtuuCGN+ztoqf+v PsRg==
MIME-Version 1.0
X-Received by 10.113.3.139 with SMTP id bw11mr12617085lbd.63.1401463770826; Fri, 30 May 2014 08:29:30 -0700 (PDT)
In-Reply-To <CACT3xuVs-RiJFcz0BWkzpvyp89Kg8Hg2UB=hJ9HR+PVhr-hKeA@mail.gmail.com>
References <CACT3xuVs-RiJFcz0BWkzpvyp89Kg8Hg2UB=hJ9HR+PVhr-hKeA@mail.gmail.com>
Date Fri, 30 May 2014 20:59:30 +0530
Subject Re: Optparse to parsing Suggestions !!
From Ganesh Pal <ganesh1pal@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=001a1134945439ce5504fa9fb6ba
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10487.1401463772.18130.python-list@python.org> (permalink)
Lines 184
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401463772 news.xs4all.nl 2975 [2001:888:2000:d::a6]:55402
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72303

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, May 30, 2014 at 7:48 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:

>
> Hello Python world ,
>
>
> I wanted suggestion on how to modify the below code to help me accomodate
> the below two cases
>
> # Here is the Sample code.
>
> def main():
>     """ ---MAIN--- """
>     parser = optparse.OptionParser(usage='%prog [options] <arg1>.]',
> version='1.0')
>    object_choice = ('super_block','blocks''files', 'directory','links')
>
>   parser.add_option("-o", "--object",
> action="store",metavar="object",default='inode',dest="object",type='choice',
> choices=object_choice,
>                      help='The object type to be corrupted [ choose from
> (' + ','.join(object_choice) + ') default: %default]',)
>
>     parser.add_option("-p",
> "--path",action="store",metavar="/mnt/",dest="path",type="string",help="The
> file or directory path in /mnt/",)
>
>     parser.add_option("-n",
> "--size",action="store",metavar="size",dest="size",default=1,type='int',help="The
> offset field)
>
>
> # Instruct optparse to parse the program's command line:
>   (options, args) = parser.parse_args()
>
>     # Build the dispatch table:
>     object_type_dictionary = {
>          "super_block":super_block_def,
>          "blocks":blocks_def,
>         "files": files_corrupt_def,
>         "directory": directory_corrupt_def,
>        "links": links_corrput_def, # no () here,we're storing function
>     }
>
>     # Lookup the object type and then call the function:
>     object_type_dictionary[options.object]()
>
>
> Sample Run
> # python corrupt.py  --object=files --path=/tmp/ --size 1000
>
>
> Questions :
>
> Case 1:  #  The  --path is optional for few for the object type.  How do I
> simulate the below behaviour
>
>          #python corrupt.py  --object=super_block  --size=1000
>
>           ==>  Should work even if --path is not given
>
>          #python corrupt.py  --object=super_block  --path=/tmp/--size 1000
>
>         ==>  If user enters --object=super_block and --path=/ifs/ should
> throw an error
>
>      saying its an invaild combinations.
>
>
>
> case 2:  # The --path is mandatory for few of the object types and  should
> complain if its not entered .
>
>           # python corrupt.py  --object=files --path=/tmp/ --size 1000
>
>
>
Can these be accomplished  with optparse using a callback.   I was reading
about this.

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


Thread

Re: Optparse to parsing Suggestions !! Ganesh Pal <ganesh1pal@gmail.com> - 2014-05-30 20:59 +0530

csiph-web