passing multiple string to a command line option

Mahmood Naderan nt_mahmood at yahoo.com
Thu Oct 6 15:51:58 EDT 2011


>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.tebeka at gmail.com>
To: comp.lang.python at googlegroups.com
Cc: python mailing list <python-list at python.org>; Mahmood Naderan <nt_mahmood at 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.




More information about the Python-list mailing list