[Tutor] Question on option parser

Andrew Robert andrew.arobert at gmail.com
Tue May 16 20:16:38 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Kent,

If I understood correctly, you meant something like this?


    #
    # Parse command line options and automatically build help/usage
    # display
    #
    if len(sys.argv) == 2:
	    infile= open(sys.argv[1],"rb").read()
	    parser=OptionParser()
            (options, args) = parser.parse_args(infile)
    else:
	    parser = OptionParser()

    parser.add_option("-m","--qmanager", dest="qmanager",
                help="\t\tQueue Manager to inquire against"),
    parser.add_option("-q","--queue", dest="queue",
                help="\t\tQueue the message will be sent to"),
    parser.add_option("-t","--to", dest="mto",
                help="\t\taddress any mail messages will be sent to")
    (options, args) = parser.parse_args()

    print options.qmanager


If so, the code generates the following deletion error.

Traceback (most recent call last):
  File "C:\Documents and Settings\Andrew Robert\My
Documents\receiver.py", line 326, in ?
    (options, args) = parser.parse_args(infile)
  File "C:\Python24\lib\optparse.py", line 1275, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "C:\Python24\lib\optparse.py", line 1322, in _process_args
    del rargs[0]
TypeError: object doesn't support item deletion


Any ideas?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEahcFDvn/4H0LjDwRAkZFAKCGapybjYnhuX9dy1DvMswskawLegCdEbbY
o/VaV2WP/ymg3dbwo3TaBi4=
=wLEn
-----END PGP SIGNATURE-----


More information about the Tutor mailing list