passing multiple string to a command line option

Mahmood Naderan nt_mahmood at yahoo.com
Thu Oct 6 11:27:51 EDT 2011


Dear developers,
Suppose I have this list in command line options:
... -b b1,b2,b3

Here is what I wrote:
parser = optparse.OptionParser()
# Benchmark options
parser.add_option("-b", "--benchmark", default="", help="The benchmark to be loaded.")
process = []
benchmarks = options.benchmark.split(',')
for bench_name in benchmarks:
    process.append(bench_name)
    
At this stage, I want to bind each process to something:
np = 2
for i in xrange(np): 
    ...
    system.cpu[i].workload = process[i]

however I get this error:

  File "configs/example/cmp.py", line 81, in <module>
    system.cpu[i].workload = process[i]
  File "/home/mahmood/gem5/src/python/m5/SimObject.py", line 627, in __setattr__
    value = param.convert(value)
  File "/home/mahmood/gem5/src/python/m5/params.py", line 236, in convert
    tmp_list = [ ParamDesc.convert(self, value) ]
  File "/home/mahmood/gem5/src/python/m5/params.py", line 159, in convert
    return self.ptype(value)
TypeError: __init__() takes exactly 1 argument (2 given)
Error setting param TmpClass.workload to bzip2_chicken

params.py is part of the simulator and I didn't wrote that.

My question is what is the simplest way to fix that?
Or is there any better idea than what I did in order to parse such command line option?

 thanks

// Naderan *Mahmood;



More information about the Python-list mailing list