Parse command line options

hue prasad413in at gmail.com
Mon Apr 18 04:00:25 EDT 2005


I am trying to parse command line options using getopt module.

I have written the following Code

import string

import getopt

def usage():
    print '''haarp_make.py -- uses getopt to recognize options

Options: -n  -- No
         -t  -- Time
         -h  -- help
         -i  -- image_file
         -o  -- Output:filename'''

    sys.exit(1)

def main():


    try:

        opts,args = getopt.getopt(sys.argv[1:], 'n:t:h:i:o:',
["Number=","time=","help=","image_file=","Output Filename="])

    except getopt.GetoptError:
        print 'Unrecognized argument or option'
        usage()
        sys.exit(0)



I have gone through getopt module from the help in python Library, but
i couldnot proceed from here.

My Task is

python  MyScriptName.py  n  t  h  i  o

How to parse those arguments, i is an Image File.
Please try to give some comments.
Hoping for a reply.




More information about the Python-list mailing list