# check if PID is already in dictionary
already_in=False
for process_id in process_ids:
- for pid in list(process_id.keys()):
+ for pid in process_id:
if int(pid) == int(command_pid):
already_in=True
break
# add process to the dictionary
if not already_in:
import types
- if type(command) == list: command=" ".join([str(c) for c in command])
+ if isinstance(command, list): command=" ".join([str(c) for c in command])
command=command.split()[0]
try:
if verbose(): print("addToKillList: %s : %s" % ( str(command_pid), command ))
def find_component_instance(self, registeredName):
anEngine = None
- keysList = list(self._listInstances_map.keys())
- i = 0
- while i < len(keysList):
- instance = keysList[i]
+ for instance in self._listInstances_map:
if find(instance,registeredName) == 0:
anEngine = self._listInstances_map[instance]
return anEngine._this()
- i = i + 1
- return anEngine._this()
+ return anEngine
#-------------------------------------------------------------------------
# Default initialization (if any)
if defaultmap is not None:
self._defaultmap.update(defaultmap)
- for name in list(self._defaultmap.keys()):
+ for name in self._defaultmap:
self.__setattr__(name,self._defaultmap[name])
## %A None argument means that no entry is created in the associated maps.
- def addAttribute(self, name, type=None, range=None, default=None, void=None):
+ def addAttribute(self, name, a_type=None, a_range=None, default=None, void=None):
"""
A None argument means that no entry is created in the associated maps.
"""
- self._typemap[name] = type
+ self._typemap[name] = a_type
- if range is not None:
- self._rangemap[name] = range
+ if a_range is not None:
+ self._rangemap[name] = a_range
if void is not None:
self._voidmap[name] = void
if name == "_typemap":
print("WARNING WARNING WARNING : changing value of _typemap by ",val)
- if name not in list(self._typemap.keys()):
+ if name not in self._typemap:
raise DevelException("The class "+str(self.__class__)+" has no attribute "+str(name))
if val is None:
if name in UNCHECKED_ATTRIBUTES:
return self.__dict__[name]
- if name not in list(self._typemap.keys()):
+ if name not in self._typemap:
raise DevelException("The class "+str(self.__class__)+" has no attribute "+str(name))
# The attribute coulb be requested while it has not been created yet (for
# example if we did't call the setter before).
ref_value = 1.3
data.addAttribute(
name = "myAttr",
- type = TypeDouble,
- range = None,
+ a_type = TypeDouble,
+ a_range = None,
default = ref_value,
void = False)
value = offset + number
setattr(self, key, value)
self._dict_keynumbers[key] = value
+ self._dict_numberkeys = {v: k for k, v in self._dict_keynumbers.items()}
## Return true if this enumerate contains the specified key string
# \param key a key string to test
Return true if this enumerate contains the specified key string
@key a key string to test
"""
- return (key in list(self._dict_keynumbers.keys()))
+ return key in self._dict_keynumbers
## Returns true if the specified integer value is defined as an identifier
# in this enumarate.
in this enumarate.
@value a value to test
"""
- return (value in list(self._dict_keynumbers.values()))
+ return value in self._dict_numberkeys
## Returns the list of keys in this enumerate.
def listkeys(self):
"""
Returns the list of keys in this enumerate.
"""
- list = list(self._dict_keynumbers.keys())
- list.sort()
- return list
+ return sorted(self._dict_keynumbers)
## Returns the list of values specified to initiate this enumerate.
def listvalues(self):
"""
Returns the list of values specified to initiate this enumerate.
"""
- list = list(self._dict_keynumbers.values())
- list.sort()
- return list
+ return sorted(self._dict_numberkeys)
## Returns the symbolic key string associated to the specified identifier value.
# \param value an integer value whose associated key string is requested.
return None
# _MEM_ We assume here that the keys and associated values are in the
# same order in their list.
- return list(self._dict_keynumbers.keys())[list(self._dict_keynumbers.values()).index(value)]
+ return self._dict_numberkeys[value]
# If not, weshould use a longer implementation such that:
#for key in self._dict_keynumbers.keys():
Create (or modify) variable with name "variableName"
and value equal "theValue".
"""
- if type(variable) == float:
+ if isinstance(variable, float):
self.myStudy.SetReal(variableName, variable)
- elif type(variable) == int:
+ elif isinstance(variable, int):
self.myStudy.SetInteger(variableName, variable)
- elif type(variable) == bool:
+ elif isinstance(variable, bool):
self.myStudy.SetBoolean(variableName, variable)
- elif type(variable) == str:
+ elif isinstance(variable, str):
self.myStudy.SetString(variableName, variable)
def get(self, variableName):