Option parser question - reading options from file as well as command line

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


Max Erickson wrote:
> Andrew Robert <andrew.arobert at gmail.com> wrote in
> news:126k3273j7kb28f at corp.supernews.com: 
> 

<snip>

<\snip>
> Check parser.usage, it is likely to look a lot like your infile.
> 
> I'm not sure, but I think you need to pass your alternative arguments 
> to parser.parse_args.
> 
> max
> 
Hi Max,

I tried passing in the read line like so:

infile= open(sys.argv[1],"rb").read()
parser=OptionParser()
print infile
(options, args) = parser.parse_args(infile)

I end up getting the following traceback.

Traceback (most recent call last):
  File "C:\Documents and Settings\Andrew Robert\My
Documents\receiver.py", line 327, 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?



More information about the Python-list mailing list