Re: passing multiple string to a command line option
Seems like self.ptype is a type that has __init__ with no arguments (other than self). You can add print type(self.ptype) as first line of convert to see what type it is (or place a breakpoint there). -- http://mail.python.org/mailman/listinfo/python-list
Re: passing multiple string to a command line option
That print command generated a lot of errors. Since that error in my first post is related to the python code in simulator, I emailed them and consulted for help. Seems that it is going to be fixed Thanks for your kindness :) // Naderan *Mahmood; - Original Message - From: Miki Tebeka miki.teb...@gmail.com To: comp.lang.pyt...@googlegroups.com Cc: python mailing list python-list@python.org; Miki Tebeka miki.teb...@gmail.com; Mahmood Naderan nt_mahm...@yahoo.com Sent: Friday, October 7, 2011 5:41 PM Subject: Re: passing multiple string to a command line option Seems like self.ptype is a type that has __init__ with no arguments (other than self). You can add print type(self.ptype) as first line of convert to see what type it is (or place a breakpoint there). -- http://mail.python.org/mailman/listinfo/python-list
passing multiple string to a command line option
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; -- http://mail.python.org/mailman/listinfo/python-list
Re: passing multiple string to a command line option
On 10/6/2011 11:27 AM, Mahmood Naderan wrote: Dear developers, Suppose I have this list in command line options: ... -b b1,b2,b3 Here is what I wrote: parser = optparse.OptionParser() If you are starting a new project, consider using argparse, which has superceded optparse. # 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, inmodule 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; -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: passing multiple string to a command line option
As far as I see, the problem is not in the command line but in system.cpu[i].workload = process[i] call tree. Without seeing the code of SimObject and params I can't tell much more. -- http://mail.python.org/mailman/listinfo/python-list
Re: passing multiple string to a command line option
Without seeing the code of SimObject and params I can't tell much more. File /home/mahmood/gem5/src/python/m5/params.py, line 159, in convert return self.ptype(value) following is part of params.py and I marked line 159. I didn't wrote this code so changing this may cause problem with other files. If there is an alternative for doing such thing passing multiple strings to command line option, it is much better. # Regular parameter description. class ParamDesc(object): file_ext = 'ptype' def __init__(self, ptype_str, ptype, *args, **kwargs): self.ptype_str = ptype_str # remember ptype only if it is provided if ptype != None: self.ptype = ptype if args: if len(args) == 1: self.desc = args[0] elif len(args) == 2: self.default = args[0] self.desc = args[1] else: raise TypeError, 'too many arguments' if kwargs.has_key('desc'): assert(not hasattr(self, 'desc')) self.desc = kwargs['desc'] del kwargs['desc'] if kwargs.has_key('default'): assert(not hasattr(self, 'default')) self.default = kwargs['default'] del kwargs['default'] if kwargs: raise TypeError, 'extra unknown kwargs %s' % kwargs if not hasattr(self, 'desc'): raise TypeError, 'desc attribute missing' def __getattr__(self, attr): if attr == 'ptype': ptype = SimObject.allClasses[self.ptype_str] assert isSimObjectClass(ptype) self.ptype = ptype return ptype raise AttributeError, '%s' object has no attribute '%s' % \ (type(self).__name__, attr) def convert(self, value): if isinstance(value, proxy.BaseProxy): value.set_param_desc(self) return value if not hasattr(self, 'ptype') and isNullPointer(value): # deferred evaluation of SimObject; continue to defer if # we're just assigning a null pointer return value if isinstance(value, self.ptype): return value if isNullPointer(value) and isSimObjectClass(self.ptype): return value return self.ptype(value) # LINE 159 def cxx_predecls(self, code): self.ptype.cxx_predecls(code) def swig_predecls(self, code): self.ptype.swig_predecls(code) def cxx_decl(self, code): code('${{self.ptype.cxx_type}} ${{self.name}};') // Naderan *Mahmood; - Original Message - From: Miki Tebeka miki.teb...@gmail.com To: comp.lang.pyt...@googlegroups.com Cc: python mailing list python-list@python.org; Mahmood Naderan nt_mahm...@yahoo.com Sent: Thursday, October 6, 2011 9:55 PM Subject: Re: passing multiple string to a command line option As far as I see, the problem is not in the command line but in system.cpu[i].workload = process[i] call tree. Without seeing the code of SimObject and params I can't tell much more. -- http://mail.python.org/mailman/listinfo/python-list