Stev0
March 12th, 2010, 04:41 AM
Working on a small program in python 3.1, using the OptParse module, however its throwing the error message every time. I figure I have something wrong in the error related if statement, but I cant find it. Any of you more experienced optparse users see the problem?
#! /usr/bin/python3.1
import sys
from optparse import OptionParser
def main():
usage = "usage: %prog [options] [target]"
parser = OptionParser()
parser.set_usage(usage)
parser.add_option("-a", "--address", action="store", dest="addy", help="blah")
parser.add_option("-r", "--range", action="store", dest="range", help="blah")
(options, args) = parser.parse_args()
if len(args) !=1:
parser.error("Please use an option to specify the target.")
addy = options.addy
do_something_with_addy(addy)now when I run the script with ./<script> -a www.test.com (http://www.test.com), it throws the error message every time. Where have I made the mistake?
#! /usr/bin/python3.1
import sys
from optparse import OptionParser
def main():
usage = "usage: %prog [options] [target]"
parser = OptionParser()
parser.set_usage(usage)
parser.add_option("-a", "--address", action="store", dest="addy", help="blah")
parser.add_option("-r", "--range", action="store", dest="range", help="blah")
(options, args) = parser.parse_args()
if len(args) !=1:
parser.error("Please use an option to specify the target.")
addy = options.addy
do_something_with_addy(addy)now when I run the script with ./<script> -a www.test.com (http://www.test.com), it throws the error message every time. Where have I made the mistake?