当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.has_key方法代码示例

本文整理汇总了Python中odict.OrderedDict.has_key方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.has_key方法的具体用法?Python OrderedDict.has_key怎么用?Python OrderedDict.has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.has_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import has_key [as 别名]
class Domain:

    def __init__(self, name):
        self.name = name
        self.sensitivities = OrderedDict()
        self.baseClassifications = OrderedDict()
        self.rawToTrans = OrderedDict()
        self.transToRaw = OrderedDict()
        self.groups = OrderedDict()

    def addSensitivity(self, sensitivity, level):
        if self.sensitivities.has_key(sensitivity) == 0:
            self.sensitivities[sensitivity] = level

    def findSensitivityByName(self, sensitivity):
        for k, v in self.sensitivities.iteritems():
#            print k,v
            if v == sensitivity:
                return sensitivity
        return None
        

    def addGroup(self, groupName):
        group = Group(groupName)
        self.groups[groupName] = group
        return group

    def addBaseClassification(self, bcName):
        baseClassification = BaseClassification(bcName)
        self.baseClassifications[bcName] = baseClassification
        return baseClassification

    def str(self):
        str = ""
        str = str + "Domain name: %s\n" % (self.name)
        str = str + "Sensitivities:"
        for key in self.sensitivities.keys():
            str = str + "%s %s\n" % (key, self.sensitivities[key])
        str = str + "Base classifications:\n"
        for key in self.baseClassifications.keys():
            str = str + str(self.baseClassifications[key])
        str = str + "Groups:\n"
        for key in self.groups.keys():
            str = str + str(self.groups[key])
#        str = str + "Raw to translated:"
#        for key in self.rawToTrans.keys():
#            str = str + "%s %s" % (key, self.rawToTrans[key])
#        str = str + "Translated to raw:"
#        for key in self.transToRaw.keys():
#            str = str + "%s %s" % (key, self.transToRaw[key])
        return str
开发者ID:tedx,项目名称:mls-tools,代码行数:53,代码来源:mcstrans.py

示例2: Model

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import has_key [as 别名]
class Model(object):

    def __init__(self):
        self.Identifiers = OrderedDict()
        self.Parameters = OrderedDict()
        self.Variables = OrderedDict()
        self.Equations = OrderedDict()
        self.DifferentialEquations = OrderedDict()
        self.Functions = OrderedDict()
        self.InitialValues = OrderedDict()
        self.Bounds = {}

        #---------Some builtin functions-------
        self.Functions['exp'] = [('math.exp')]
        self.Functions['log'] = [('math.log')]
        self.Functions['log10'] = [('math.log10')]
        self.Functions['pow'] = [('math.pow')]
        self.Functions['sqrt'] = [('math.sqrt')]


        self.Functions['sin'] = [('math.sin')]
        self.Functions['cos'] = [('math.cos')]
        self.Functions['tan'] = [('math.tan')]
        self.Functions['hypot'] = [('math.hypot')]

        self.Functions['asin'] = [('math.asin')]
        self.Functions['acos'] = [('math.acos')]
        self.Functions['atan'] = [('math.atan')]


        self.Functions['radians'] = [('math.radians')]
        self.Functions['degrees'] = [('math.degrees')]


    def addInitialValue(self, name, value):
        self.InitialValues[name] = value

    def addIdentifier(self, name):
        if name not in self.Identifiers.keys():
            self.Identifiers[name] = 'id_' + str(len(self.Identifiers)).zfill(3)

        return self.Identifiers[name]

    def addVariable(self, id):
        attrs_present, parts = has_attributes(id)
        if attrs_present:
            raise EquationSenseError, 'Cannot use attributes in equation'

        if not self.Variables.has_key(id):
            self.Variables[id] = 0.0

        return 'x[' + str(self.Variables.index(id)) + ']'

    def addEquation(self, LHS, RHS, eqn_id = None):
        if eqn_id is None:
            eqn_id = '#' + str(len(self.Equations) + 1)

        self.Equations[eqn_id] = (LHS, RHS)

    def addVariableBound(self, id, lower_bound, upper_bound):
        existing = self.Bounds.get(id, None)

        if existing:
            if lower_bound is not None:
                existing = (float(lower_bound), existing[1])
            if upper_bound is not None:
                existing = (existing[0], float(upper_bound))

            self.Bounds[id] = existing
        else:
            if lower_bound is not None:
                lower_bound = float(lower_bound)
            if upper_bound is not None:
                upper_bound = float(upper_bound)

            self.Bounds[id] = (lower_bound, upper_bound)


    def addParameter(self, id, value):

        attrs_present, parts = has_attributes(id)
        if attrs_present:
            actual_id = id.split('.')[0]
            parts = [p.lower() for p in parts]

            if len(parts) == 1 and 'guess' in parts:
                self.addInitialValue(actual_id, value)
            elif len(parts) == 1 and 'min' in parts:
                self.addVariableBound(actual_id, value, None)
            elif len(parts) == 1 and 'max' in parts:
                self.addVariableBound(actual_id, None, value)
            else:
                raise EquationSenseError, 'Only supports guess, min and max attributes'

        else:
            #Check if the id is in the variable map, if it is delete it
            #and place it in the parameters map

            #This happens when a parameters is defined after its use
            #in an equation
#.........这里部分代码省略.........
开发者ID:AndreLester,项目名称:xyzsolve,代码行数:103,代码来源:Model.py

示例3: Config

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import has_key [as 别名]
class Config(dict):
        
    def __init__(self, user_file=None):
        self.config = OrderedDict()
        self.user_file = user_file
        self.update(self.get_running_config())
        
    def set_user_file(self, user_file):
        self.user_file = user_file
        
    def add_category(self, category):
        if not self.config.has_key(category):
            self.config[category] = OrderedDict()
            
    def add_setting(self, category, setting, value, about='', type=0, stub=False, **kwargs):
        assert category != None, 'Must specify a category'
        assert setting != None, 'Must specify a setting'
        assert value != None, 'Must specify a value'
        self.add_category(category)
        if not self.config[category].has_key(setting):
            self.config[category][setting] = OrderedDict()
        self.config[category][setting]['value'] = value
        if not stub:
            self.config[category][setting]['about'] = about
            self.config[category][setting]['type'] = type
            for k in kwargs:
                self.config[category][setting][k] = kwargs[k]
        self.update(self.get_running_config())
        
    def get_setting(self, category, setting, complete=False):
        assert category != None, 'Must specify a category'
        assert setting != None, 'Must specify a setting'
        assert self.config.has_key(category), 'Category does not exist'
        assert self.config[category].has_key(setting), 'Setting in category does not exist'
        assert self.config[category][setting].has_key('value'), 'Setting in category has no value'
        if complete:
            return self.config[category][setting]
        else:
            return self.config[category][setting]['value']
        
    def update_setting_value(self, category, setting, value):
        assert category != None, 'Must specify a category'
        assert setting != None, 'Must specify a setting'
        assert value != None, 'Must specify a value'
        if self.config.has_key(category):
            if self.config[category].has_key(setting):
                self.config[category][setting]['value'] = value
                self.update(self.get_running_config())
    
    def get_settings(self, category):
        assert category != None, 'Must specify a category'
        assert self.config.has_key(category), 'Category does not exist'
        return self.config[category].keys()
    
    def get_categories(self):
        return self.config.keys()
        
    def update_from_string(self, json_config):
        try:
            config = json.loads(json_config)
            for c in config.keys():
                for s in config[c].keys():
                    self.update_setting_value(c, s, config[c][s]['value'])
        except ValueError:
            sys.stderr.write('Empty or malformed config file found!\n')
        
                
    def update_from_user_file(self):
        if self.user_file and os.path.isfile(self.user_file):
            with open(self.user_file, 'r') as f:
                return self.update_from_string(f.read())
            
    def get_running_config(self):
        tmpCfg = {}
        for category in self.config.keys():
            tmpCfg[category] = {}
            for setting in self.config[category].keys():
                tmpCfg[category][setting] = self.config[category][setting]['value']
        return tmpCfg
            
    def __str__(self):
        return json.dumps(self.get_running_config(), separators=(',', ':'), sort_keys=True)        
开发者ID:RyanHope,项目名称:jsonConfig,代码行数:84,代码来源:config.py


注:本文中的odict.OrderedDict.has_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。