Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72300
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!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; '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; 'code.': 0.18; 'entered': 0.20; 'command': 0.22; 'saying': 0.22; 'error': 0.23; 'parse': 0.24; 'skip:" 30': 0.26; 'skip:" 20': 0.27; 'function': 0.29; 'skip:p 30': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'file': 0.32; 'run': 0.32; 'cases': 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; '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; 'world': 0.66; 'here': 0.66; 'sample': 0.67; '\xc2\xa0\xc2\xa0': 0.74; '==>': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=VAkyzr6ekAJlF+f9xVTMwixmzIrimXTGgQn99qerUE8=; b=yoJur6xzvja3UHmm5xItexI7wG68a/3cKlQcjirRtCpiyhATfS2lhDhafv96RAI/MP InmNFjya1fZK5FD5VhF+3iMtiEfv1/mwCtylIL8cv2sTeWEANv2tVBarAb46s09NDbKc LD0Y6h0yGg3IKiwRJA1YXfD/7pIkGpT37BNIUgbCa6r5llnZGNzuDdDJg28sx5ty8scO CCAV+SOUbyVfraWtx7JDLLtL8twH9s4xVECWFz3thNOF7x19D8xSnQ8s+/OX1YwgT+sj lYRTFWWepLDKdOsvc617JmthQUZXKTqV9J5fLyguek8OKdRfUdeUJWs9/dwh2f6GyxC3 2AtQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.112.150.130 with SMTP id ui2mr2902705lbb.80.1401459497786; Fri, 30 May 2014 07:18:17 -0700 (PDT) |
| Date | Fri, 30 May 2014 19:48:17 +0530 |
| Subject | Optparse to parsing Suggestions !! |
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| To | python-list@python.org |
| Content-Type | multipart/alternative; boundary=047d7b3a821a88633804fa9eb75a |
| 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.10485.1401459907.18130.python-list@python.org> (permalink) |
| Lines | 152 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1401459907 news.xs4all.nl 2844 [2001:888:2000:d::a6]:44902 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:72300 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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
Regards,
Ganesh
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Optparse to parsing Suggestions !! Ganesh Pal <ganesh1pal@gmail.com> - 2014-05-30 19:48 +0530
csiph-web